-
Notifications
You must be signed in to change notification settings - Fork 18
/
debug.js
34 lines (26 loc) · 922 Bytes
/
debug.js
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
32
33
34
'use strict'
var util = require('util');
module.exports = debug
function debug (namespace) {
if (!debug.logger) {
throw Error('debug called before pino-debug initialized, ' +
'register pino-debug at the top of your entry point')
}
var logger = debug.logger.child({'ns': namespace})
var log = Array.from(debug.map.keys()).map(function (rx) {
return rx.test(namespace) && logger[debug.map.get(rx)]
}).filter(Boolean)[0] || logger.debug
function disabled () {}
disabled.enabled = false
function enabled () {
let message = util.format.apply(util, arguments) // this is how debug.js formats argeuments
return log.apply(logger, [message])
}
enabled.enabled = true
var fn = debug.enabled(namespace) ? enabled : disabled
fn.extend = function (subNamespace, delimiter) {
return debug(namespace + (delimiter || ':') + subNamespace)
}
fn.namespace = namespace
return fn
}