debug-logfmt 1.1.0 → 1.2.0
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/index.js +34 -9
- package/package.json +4 -2
- /package/{LICENSE → LICENSE.md} +0 -0
package/index.js
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
+
const timeSpan = require('@kikobeats/time-span')({
|
|
4
|
+
format: require('pretty-ms')
|
|
5
|
+
})
|
|
6
|
+
const { encode } = require('@jclem/logfmt2')
|
|
3
7
|
const origDebug = require('debug')
|
|
4
8
|
|
|
5
9
|
/**
|
|
@@ -19,20 +23,41 @@ if (process.env.DEBUG_COLORS === 'false') {
|
|
|
19
23
|
}
|
|
20
24
|
}
|
|
21
25
|
|
|
22
|
-
const
|
|
23
|
-
const debug = require('debug-fabulous')(origDebug)
|
|
26
|
+
const createDebug = require('debug-fabulous')(origDebug)
|
|
24
27
|
|
|
25
28
|
const LEVELS = ['info', 'warn', 'error']
|
|
26
29
|
|
|
27
30
|
const createLogger =
|
|
28
31
|
log =>
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
32
|
+
(...args) =>
|
|
33
|
+
log(
|
|
34
|
+
args.map(arg => (typeof arg === 'string' ? arg : encode(arg))).join(' ')
|
|
35
|
+
)
|
|
33
36
|
|
|
34
37
|
module.exports = (env, { levels = LEVELS } = {}) => {
|
|
35
|
-
const
|
|
36
|
-
levels.forEach(
|
|
37
|
-
|
|
38
|
+
const debug = createLogger(createDebug(env))
|
|
39
|
+
levels.forEach(
|
|
40
|
+
level => (debug[level] = createLogger(createDebug(`${env}:${level}`)))
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
debug.duration = (...args) => {
|
|
44
|
+
const duration = timeSpan()
|
|
45
|
+
|
|
46
|
+
const create =
|
|
47
|
+
type =>
|
|
48
|
+
(...opts) => {
|
|
49
|
+
;(type ? debug[type] : debug)(...args, ...opts, {
|
|
50
|
+
duration: duration()
|
|
51
|
+
})
|
|
52
|
+
return true
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const fn = create()
|
|
56
|
+
fn.error = create('error')
|
|
57
|
+
fn.info = create('info')
|
|
58
|
+
|
|
59
|
+
return fn
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return debug
|
|
38
63
|
}
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "debug-logfmt",
|
|
3
3
|
"description": "debug module using logfmt format",
|
|
4
4
|
"homepage": "https://github.com/Kikobeats/debug-logfmt",
|
|
5
|
-
"version": "1.
|
|
5
|
+
"version": "1.2.0",
|
|
6
6
|
"main": "index.js",
|
|
7
7
|
"author": {
|
|
8
8
|
"email": "josefrancisco.verdu@gmail.com",
|
|
@@ -28,7 +28,9 @@
|
|
|
28
28
|
],
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"@jclem/logfmt2": "~2.4.3",
|
|
31
|
-
"
|
|
31
|
+
"@kikobeats/time-span": "~1.0.2",
|
|
32
|
+
"debug-fabulous": "~2.0.2",
|
|
33
|
+
"pretty-ms": "~7.0.1"
|
|
32
34
|
},
|
|
33
35
|
"devDependencies": {
|
|
34
36
|
"@commitlint/cli": "latest",
|
/package/{LICENSE → LICENSE.md}
RENAMED
|
File without changes
|