diff --git a/index.js b/index.js index 706b9d7..e8a15c4 100644 --- a/index.js +++ b/index.js @@ -15,19 +15,19 @@ function getLogger(namespace) { var logger = sparkles(namespace); levels.forEach(function(level){ - logger[level] = makeLogLevel(level); + logger[level] = makeLogLevel(logger, level); }); return logger; } -function makeLogLevel(level) { +function makeLogLevel(self, level) { return function(msg){ if (typeof msg === 'string') { msg = format.apply(null, arguments); } - this.emit(level, msg); + self.emit(level, msg); }; } diff --git a/test/index.js b/test/index.js index 4c833c9..6d504b0 100644 --- a/test/index.js +++ b/test/index.js @@ -4,21 +4,21 @@ var expect = require('expect'); var glogg = require('../'); -describe('glogg', function(){ +describe('glogg', function() { var logger; - beforeEach(function(done){ + beforeEach(function(done) { logger = glogg('glogg-test'); done(); }); - afterEach(function(done){ + afterEach(function(done) { logger.remove(); done(); }); - it('emits a debug event when debug method is called', function(done){ + it('emits a debug event when debug method is called', function(done) { logger.on('debug', function(msg){ expect(msg).toEqual('test'); done(); @@ -27,7 +27,7 @@ describe('glogg', function(){ logger.debug('test'); }); - it('emits a info event when info method is called', function(done){ + it('emits a info event when info method is called', function(done) { logger.on('info', function(msg){ expect(msg).toEqual('test'); done(); @@ -36,7 +36,7 @@ describe('glogg', function(){ logger.info('test'); }); - it('emits a warn event when warn method is called', function(done){ + it('emits a warn event when warn method is called', function(done) { logger.on('warn', function(msg){ expect(msg).toEqual('test'); done(); @@ -45,7 +45,7 @@ describe('glogg', function(){ logger.warn('test'); }); - it('emits a error event when error method is called', function(done){ + it('emits a error event when error method is called', function(done) { logger.on('error', function(msg){ expect(msg).toEqual('test'); done(); @@ -54,7 +54,7 @@ describe('glogg', function(){ logger.error('test'); }); - it('formats a string message with util.format syntax', function(done){ + it('formats a string message with util.format syntax', function(done) { logger.on('debug', function(msg){ expect(msg).toEqual('test something'); done(); @@ -63,7 +63,7 @@ describe('glogg', function(){ logger.debug('test %s', 'something'); }); - it('does not format a non-string message', function(done){ + it('does not format a non-string message', function(done) { var expected = { test: 'something' }; logger.on('debug', function(msg){ @@ -73,4 +73,15 @@ describe('glogg', function(){ logger.debug(expected); }); + + it('allows you to "destructure" the individual log-level functions', function(done) { + var debug = logger.debug; + + logger.on('debug', function(msg){ + expect(msg).toEqual('test'); + done(); + }); + + debug('test'); + }); });