Skip to content

Commit 1e9d38c

Browse files
cache enabled status per-logger (#799)
Co-authored-by: Qix <Qix-@users.noreply.github.com>
1 parent 0d3d66b commit 1e9d38c

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/common.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ function setup(env) {
6060
function createDebug(namespace) {
6161
let prevTime;
6262
let enableOverride = null;
63+
let namespacesCache;
64+
let enabledCache;
6365

6466
function debug(...args) {
6567
// Disabled?
@@ -120,7 +122,17 @@ function setup(env) {
120122
Object.defineProperty(debug, 'enabled', {
121123
enumerable: true,
122124
configurable: false,
123-
get: () => enableOverride === null ? createDebug.enabled(namespace) : enableOverride,
125+
get: () => {
126+
if (enableOverride !== null) {
127+
return enableOverride;
128+
}
129+
if (namespacesCache !== createDebug.namespaces) {
130+
namespacesCache = createDebug.namespaces;
131+
enabledCache = createDebug.enabled(namespace);
132+
}
133+
134+
return enabledCache;
135+
},
124136
set: v => {
125137
enableOverride = v;
126138
}
@@ -149,6 +161,7 @@ function setup(env) {
149161
*/
150162
function enable(namespaces) {
151163
createDebug.save(namespaces);
164+
createDebug.namespaces = namespaces;
152165

153166
createDebug.names = [];
154167
createDebug.skips = [];

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy