Skip to content

Commit

Permalink
common: Added silent log level and option to specify custom log levels (
Browse files Browse the repository at this point in the history
  • Loading branch information
kjin authored and stephenplusplus committed Dec 29, 2016
1 parent c10bc53 commit 44ea645
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
7 changes: 5 additions & 2 deletions packages/common/src/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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) {
Expand All @@ -55,7 +58,7 @@ function logger(options) {
options = options || {};

return logDriver({
levels: LEVELS,
levels: options.levels || LEVELS,

level: options.level || 'error',

Expand Down
6 changes: 6 additions & 0 deletions packages/common/test/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ var assert = require('assert');
var proxyquire = require('proxyquire');

var LEVELS = [
'silent',
'error',
'warn',
'info',
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 44ea645

Please sign in to comment.