Skip to content

Commit

Permalink
copy custom logger to namespace extension (fixes #646)
Browse files Browse the repository at this point in the history
  • Loading branch information
Qix- committed Dec 19, 2018
1 parent 5528572 commit 825d35a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,9 @@ function setup(env) {
}

function extend(namespace, delimiter) {
return createDebug(this.namespace + (typeof delimiter === 'undefined' ? ':' : delimiter) + namespace);
const newDebug = createDebug(this.namespace + (typeof delimiter === 'undefined' ? ':' : delimiter) + namespace);
newDebug.log = this.log;
return newDebug;
}

/**
Expand Down
8 changes: 8 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,14 @@ describe('debug', () => {
const logBar = log.extend('bar', '');
assert.deepStrictEqual(logBar.namespace, 'foobar');
});

it('should keep the log function between extensions', () => {
const log = debug('foo');
log.log = () => {};

const logBar = log.extend('bar');
assert.deepStrictEqual(log.log, logBar.log);
});
});

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

0 comments on commit 825d35a

Please sign in to comment.