Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

common: Added silent log level and option to specify custom log levels #1900

Merged
merged 2 commits into from
Dec 29, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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