debug-logfmt 1.4.17 → 1.4.18
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 +20 -2
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "debug-logfmt",
|
|
3
3
|
"description": "Drop-in debug logger that emits logfmt key=value lines for structured Heroku-style logs.",
|
|
4
4
|
"homepage": "https://github.com/Kikobeats/debug-logfmt",
|
|
5
|
-
"version": "1.4.
|
|
5
|
+
"version": "1.4.18",
|
|
6
6
|
"types": "./src/index.d.ts",
|
|
7
7
|
"main": "src/index.js",
|
|
8
8
|
"exports": {
|
package/src/index.js
CHANGED
|
@@ -27,9 +27,27 @@ const createDebug = require('./lazy')(origDebug)
|
|
|
27
27
|
|
|
28
28
|
const LEVELS = ['info', 'warn', 'error']
|
|
29
29
|
|
|
30
|
+
const tracksNamespaces = 'namespaces' in origDebug
|
|
31
|
+
|
|
32
|
+
const memoizeByNamespaces = compute => {
|
|
33
|
+
// Not a namespaces string, so the first read always misses.
|
|
34
|
+
let namespaces = {}
|
|
35
|
+
let cached
|
|
36
|
+
return () => {
|
|
37
|
+
if (origDebug.namespaces !== namespaces) {
|
|
38
|
+
// Commit the key after compute so a failed read is tried again.
|
|
39
|
+
cached = compute()
|
|
40
|
+
namespaces = origDebug.namespaces
|
|
41
|
+
}
|
|
42
|
+
return cached
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
30
46
|
const createLogger = log => {
|
|
47
|
+
const isEnabled = tracksNamespaces ? memoizeByNamespaces(() => log.enabled) : () => log.enabled
|
|
48
|
+
|
|
31
49
|
const logger = (...args) => {
|
|
32
|
-
if (!
|
|
50
|
+
if (!isEnabled()) return
|
|
33
51
|
|
|
34
52
|
log(
|
|
35
53
|
args.reduce((result, arg, index) => {
|
|
@@ -42,7 +60,7 @@ const createLogger = log => {
|
|
|
42
60
|
|
|
43
61
|
Object.defineProperty(logger, 'enabled', {
|
|
44
62
|
enumerable: true,
|
|
45
|
-
get:
|
|
63
|
+
get: isEnabled
|
|
46
64
|
})
|
|
47
65
|
|
|
48
66
|
return logger
|