Skip to content

Commit 0a1e8f1

Browse files
committed
fix(debug): basic namespace filtering
1 parent 0957178 commit 0a1e8f1

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/runtime/npm/debug.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,16 @@ import type { Debug, Debugger, Formatters } from "debug";
44

55
function createDebug(namespace: string): Debugger {
66
return Object.assign(
7-
(formatter: string, ...args: any[]) => console.debug(formatter, ...args),
7+
(...args: any[]) => {
8+
const env = globalThis.process?.env.DEBUG;
9+
if (!env || (env !== "*" && !env.startsWith(namespace))) return;
10+
console.debug(...args);
11+
},
812
{
913
color: "#000000",
1014
diff: 0,
1115
enabled: true,
12-
log: console.debug,
16+
log: console.debug.bind(console),
1317
namespace,
1418
destroy: () => false,
1519
extend: (ns: string, _del?: string) => createDebug(namespace + ns),
@@ -25,7 +29,7 @@ const debug: Debug = Object.assign(createDebug, {
2529
formatArgs(this: Debugger, args: any[]) {
2630
args[0] = `${this.namespace} ${args[0]}`;
2731
},
28-
log: console.debug,
32+
log: console.debug.bind(console),
2933
selectColor: (_namespace: string) => 0,
3034
humanize: (num: any) => `${num}ms` as any,
3135
inspectOpts: {},

0 commit comments

Comments
 (0)