From 825d35a2da0a9fa115baffea2f07d22b876332fc Mon Sep 17 00:00:00 2001 From: Josh Junon Date: Wed, 19 Dec 2018 04:56:06 +0100 Subject: [PATCH] copy custom logger to namespace extension (fixes #646) --- src/common.js | 4 +++- test.js | 8 ++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/common.js b/src/common.js index 0b6d0b64..2f82b8dc 100644 --- a/src/common.js +++ b/src/common.js @@ -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; } /** diff --git a/test.js b/test.js index 460f9759..f61e079b 100644 --- a/test.js +++ b/test.js @@ -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)', () => {