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 22, 2018
1 parent d0e498f commit 57ef085
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 @@ -80,6 +80,14 @@ describe('debug', () => {
const logBar = log.extend('bar', '');
expect(logBar.namespace).to.be.equal('foobar');
});

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

const logBar = log.extend('bar');
expect(log.log).to.be.equal(logBar.log);
});
});

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

0 comments on commit 57ef085

Please sign in to comment.