-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcommon.js
More file actions
31 lines (25 loc) · 832 Bytes
/
common.js
File metadata and controls
31 lines (25 loc) · 832 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
'use strict'
function consolePrefix (f, p) {
return function () {
let a = [...arguments]
if (typeof a[0] === 'string') a.unshift('%c[' + p + ']%c ' + a.shift())
else a.unshift('%c[' + p + ']%c')
a = [a[0]].concat(['font-weight: bold', 'color: inherit', a.slice(1)])
f.apply(console, a)
}
}
module.exports = function ZeroNetBrowserCommon (opt) {
const self = this
self.browser = true
self.logger = name => {
const l = consolePrefix(console.log, name)
l.info = l
l.log = l
l.debug = opt.debug ? consolePrefix(console.info, 'DEBUG/' + name) : () => {}
l.trace = opt.debug ? consolePrefix(console.info, 'TRACE/' + name) : () => {}
l.warn = consolePrefix(console.warn, name)
l.error = l.fatal = consolePrefix(console.error, name)
return l
}
self.title = () => {}
}