Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Copy custom logger to namespace extension #660

Merged
merged 1 commit into from
Dec 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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