Skip to content

Commit

Permalink
Enable use of custom log function (#379)
Browse files Browse the repository at this point in the history
* Enable use of custom log function

* Add test for custom log function
  • Loading branch information
hsiliev authored and thebigredgeek committed Dec 18, 2016
1 parent 1c625d4 commit 50ffa9d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
2 changes: 1 addition & 1 deletion debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
21 changes: 20 additions & 1 deletion test/debug_spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { expect } from 'chai';
import { assert, spy } from 'sinon';

import debug from '../index';

Expand All @@ -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);
});
});
});
});

0 comments on commit 50ffa9d

Please sign in to comment.