diff --git a/packages/common/src/logger.js b/packages/common/src/logger.js index 0d76e6f7e54..14b9959c585 100644 --- a/packages/common/src/logger.js +++ b/packages/common/src/logger.js @@ -25,10 +25,11 @@ var is = require('is'); var logDriver = require('log-driver'); /** - * A list of log levels. + * The default list of log levels. * @type {string[]} */ var LEVELS = [ + 'silent', 'error', 'warn', 'info', @@ -43,6 +44,8 @@ var LEVELS = [ * treated as `options.level`. * @param {string=} options.level - The minimum log level that will print to the * console. (Default: `error`) + * @param {string[]=} options.levels - The list of levels to use. (Default: + * logger.LEVELS) * @param {string=} options.tag - A tag to use in log messages. */ function logger(options) { @@ -55,7 +58,7 @@ function logger(options) { options = options || {}; return logDriver({ - levels: LEVELS, + levels: options.levels || LEVELS, level: options.level || 'error', diff --git a/packages/common/test/logger.js b/packages/common/test/logger.js index bcf87514f54..51a38c04ca3 100644 --- a/packages/common/test/logger.js +++ b/packages/common/test/logger.js @@ -20,6 +20,7 @@ var assert = require('assert'); var proxyquire = require('proxyquire'); var LEVELS = [ + 'silent', 'error', 'warn', 'info', @@ -48,6 +49,11 @@ describe('logger base-functionality', function() { assert.deepEqual(logger().levels, LEVELS); }); + it('should create a logger with custom levels', function() { + var customLevels = [ 'level-1', 'level-2', 'level-3' ]; + assert.deepEqual(logger({ levels: customLevels }).levels, customLevels); + }); + it('should use a specified level', function() { var level = 'level'; assert.strictEqual(logger({ level: level }).level, level);