Skip to content

Commit 2fb7d08

Browse files
committed
copy custom logger to namespace extension (fixes #646)
1 parent c0127b1 commit 2fb7d08

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/common.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,9 @@ function setup(env) {
143143
}
144144

145145
function extend(namespace, delimiter) {
146-
return createDebug(this.namespace + (typeof delimiter === 'undefined' ? ':' : delimiter) + namespace);
146+
const newDebug = createDebug(this.namespace + (typeof delimiter === 'undefined' ? ':' : delimiter) + namespace);
147+
newDebug.log = this.log;
148+
return newDebug;
147149
}
148150

149151
/**

test.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,14 @@ describe('debug', () => {
7070
const logBar = log.extend('bar', '');
7171
assert.deepStrictEqual(logBar.namespace, 'foobar');
7272
});
73+
74+
it('should keep the log function between extensions', () => {
75+
const log = debug('foo');
76+
log.log = () => {};
77+
78+
const logBar = log.extend('bar');
79+
assert.deepStrictEqual(log.log, logBar.log);
80+
});
7381
});
7482

7583
describe('rebuild namespaces string (disable)', () => {

0 commit comments

Comments
 (0)