debug-logfmt 1.4.6 → 1.4.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/index.js +31 -16
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -27,36 +27,51 @@ const createDebug = require('./lazy')(origDebug)
|
|
|
27
27
|
|
|
28
28
|
const LEVELS = ['info', 'warn', 'error']
|
|
29
29
|
|
|
30
|
-
const createLogger =
|
|
31
|
-
|
|
32
|
-
(
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
)
|
|
30
|
+
const createLogger = log => {
|
|
31
|
+
const logger = (...args) => {
|
|
32
|
+
if (!log.enabled) return
|
|
33
|
+
|
|
34
|
+
log(
|
|
35
|
+
args.reduce((result, arg, index) => {
|
|
36
|
+
const encoded = typeof arg === 'string' ? arg : encode(arg)
|
|
37
|
+
if (!encoded) return result
|
|
38
|
+
return result + (index > 0 ? ' ' : '') + encoded
|
|
39
|
+
}, '')
|
|
40
|
+
)
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
Object.defineProperty(logger, 'enabled', {
|
|
44
|
+
enumerable: true,
|
|
45
|
+
get: () => log.enabled
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
return logger
|
|
49
|
+
}
|
|
40
50
|
|
|
41
51
|
module.exports = (env, { levels = LEVELS } = {}) => {
|
|
42
52
|
const debug = createLogger(createDebug(env))
|
|
43
53
|
levels.forEach(level => (debug[level] = createLogger(createDebug(`${env}:${level}`))))
|
|
44
54
|
|
|
45
55
|
debug.duration = (...args) => {
|
|
46
|
-
|
|
56
|
+
let duration = debug.enabled ? timeSpan() : undefined
|
|
47
57
|
|
|
48
58
|
const create =
|
|
49
|
-
|
|
59
|
+
logger =>
|
|
50
60
|
(...opts) => {
|
|
51
|
-
|
|
61
|
+
if (!logger.enabled) return true
|
|
62
|
+
|
|
63
|
+
duration = duration || timeSpan()
|
|
64
|
+
|
|
65
|
+
logger(...args, ...opts, {
|
|
52
66
|
duration: duration()
|
|
53
67
|
})
|
|
68
|
+
|
|
54
69
|
return true
|
|
55
70
|
}
|
|
56
71
|
|
|
57
|
-
const fn = create()
|
|
58
|
-
fn.error = create(
|
|
59
|
-
fn.info = create(
|
|
72
|
+
const fn = create(debug)
|
|
73
|
+
fn.error = create(debug.error)
|
|
74
|
+
fn.info = create(debug.info)
|
|
60
75
|
|
|
61
76
|
return fn
|
|
62
77
|
}
|