diff --git a/debug.js b/debug.js index 7b0632db..4d3c7f27 100644 --- a/debug.js +++ b/debug.js @@ -110,7 +110,7 @@ function createDebug(namespace) { // apply env-specific formatting (colors, etc.) exports.formatArgs.call(self, args); - var logFn = enabled.log || exports.log || console.log.bind(console); + var logFn = debug.log || exports.log || console.log.bind(console); logFn.apply(self, args); } diff --git a/test/debug_spec.js b/test/debug_spec.js index b0339218..136937aa 100644 --- a/test/debug_spec.js +++ b/test/debug_spec.js @@ -1,4 +1,5 @@ import { expect } from 'chai'; +import { assert, spy } from 'sinon'; import debug from '../index'; @@ -9,4 +10,22 @@ describe('debug', () => { log('hello world'); }); }); -}) + + describe('custom functions', () => { + let log; + + beforeEach(() => { + debug.enable('test'); + log = debug('test'); + }); + + context('with log function', () => { + it('uses it', () => { + log.log = spy(); + log('using custom log function'); + + assert.calledOnce(log.log); + }); + }); + }); +});