Comparing version 1.4.2 to 1.4.3
{ | ||
"name": "errorlog", | ||
"description": "Yet another logger for Node", | ||
"version": "1.4.2", | ||
"version": "1.4.3", | ||
"author": { | ||
@@ -6,0 +6,0 @@ "name": "Pier Fumagalli", |
@@ -39,3 +39,3 @@ 'use strict'; | ||
var json = JSON.stringify(arg[ptr]); | ||
if ((json !== '{}') || (!(arg[ptr] instanceof Error))) { | ||
if ((json !== '{}') && (! util.isError(arg[ptr]))) { | ||
msg += '\n >>> ' + json; | ||
@@ -94,3 +94,3 @@ } | ||
// From level to number | ||
function parseLevel(level) { | ||
function parseLevel(level, defaultLevel) { | ||
if (typeof level === 'number') return level; | ||
@@ -116,4 +116,4 @@ | ||
// Still here? Default, info | ||
return null; | ||
// Still here? Default... | ||
return defaultLevel; | ||
} | ||
@@ -147,3 +147,3 @@ | ||
if (options.category) category = String(options.category) || null; | ||
if (options.level) level = parseLevel(options.level) || null; | ||
if (options.level) level = parseLevel(options.level, null); | ||
if (options.logger) log = wrap(options.logger); | ||
@@ -240,3 +240,3 @@ } | ||
get: function() { return defaultLevel }, | ||
set: function(level) { defaultLevel = parseLevel(level) || INFO } | ||
set: function(level) { defaultLevel = parseLevel(level, INFO) } | ||
}, | ||
@@ -243,0 +243,0 @@ 'defaultColorize': { |
'use strict'; | ||
var expect = require('chai').expect; | ||
var simplelog = require('../src/errorlog.js'); | ||
var errorlog = require('../src/errorlog.js'); | ||
// No color test! | ||
simplelog.defaultColorize = false; | ||
errorlog.defaultColorize = false; | ||
@@ -27,6 +27,6 @@ // A regular expression matching an ISO date | ||
// Inject the default stream | ||
var stream = simplelog.defaultLog = new Stream(); | ||
var stream = errorlog.defaultLog = new Stream(); | ||
// The shared log for testing | ||
var log = simplelog(); | ||
var log = errorlog(); | ||
@@ -36,12 +36,12 @@ describe('Simple log test', function() { | ||
it('should expose some basic properties', function() { | ||
expect(simplelog).to.be.a('function'); | ||
expect(simplelog.ALL ).to.equal( -1); | ||
expect(simplelog.TRACE).to.equal( 0); | ||
expect(simplelog.DEBUG).to.equal(100); | ||
expect(simplelog.INFO ).to.equal(200); | ||
expect(simplelog.WARN ).to.equal(300); | ||
expect(simplelog.ERROR).to.equal(400); | ||
expect(simplelog.OFF ) .to.equal(Number.MAX_SAFE_INTEGER); | ||
expect(simplelog.defaultLog).to.be.a('function'); | ||
expect(simplelog.defaultLevel).to.equal(simplelog.INFO); | ||
expect(errorlog).to.be.a('function'); | ||
expect(errorlog.ALL ).to.equal( -1); | ||
expect(errorlog.TRACE).to.equal( 0); | ||
expect(errorlog.DEBUG).to.equal(100); | ||
expect(errorlog.INFO ).to.equal(200); | ||
expect(errorlog.WARN ).to.equal(300); | ||
expect(errorlog.ERROR).to.equal(400); | ||
expect(errorlog.OFF ) .to.equal(Number.MAX_SAFE_INTEGER); | ||
expect(errorlog.defaultLog).to.be.a('function'); | ||
expect(errorlog.defaultLevel).to.equal(errorlog.INFO); | ||
}); | ||
@@ -85,3 +85,3 @@ | ||
it('should use a category', function() { | ||
simplelog('my own category')('A categorized message'); | ||
errorlog('my own category')('A categorized message'); | ||
expect(stream.check()).to.equal(' LOG - my own category: A categorized message'); | ||
@@ -94,3 +94,3 @@ }); | ||
log('this should go to the shared logger'); | ||
simplelog(logger)('different logger'); | ||
errorlog(logger)('different logger'); | ||
@@ -105,3 +105,3 @@ expect(stream.check()).to.equal(' LOG - this should go to the shared logger'); | ||
log('this should go to the shared logger'); | ||
simplelog({logger: logger, category: 'foobar'})('different logger'); | ||
errorlog({logger: logger, category: 'foobar'})('different logger'); | ||
@@ -117,3 +117,3 @@ expect(stream.check()).to.equal(' LOG - this should go to the shared logger'); | ||
log('this should go to the shared logger'); | ||
simplelog({logger: logger})('different logger'); | ||
errorlog({logger: logger})('different logger'); | ||
@@ -129,3 +129,3 @@ expect(stream.check()).to.equal(' LOG - this should go to the shared logger'); | ||
log('this should go to the shared logger'); | ||
simplelog({logger: logger, category: 'foobar'})('different logger'); | ||
errorlog({logger: logger, category: 'foobar'})('different logger'); | ||
@@ -139,3 +139,3 @@ expect(stream.check()).to.equal(' LOG - this should go to the shared logger'); | ||
var append = function(more) { data.push(more) }; | ||
var logger = simplelog({level: 'all', logger: append}); | ||
var logger = errorlog({level: 'all', logger: append}); | ||
logger.debug('debug'); | ||
@@ -152,3 +152,3 @@ logger.info ('info'); | ||
var append = function(more) { data.push(more) }; | ||
var logger = simplelog({level: 'debug', logger: append}); | ||
var logger = errorlog({level: 'debug', logger: append}); | ||
logger.debug('debug'); | ||
@@ -165,3 +165,3 @@ logger.info ('info'); | ||
var append = function(more) { data.push(more) }; | ||
var logger = simplelog({level: 'info', logger: append}); | ||
var logger = errorlog({level: 'info', logger: append}); | ||
logger.debug('debug'); | ||
@@ -178,3 +178,3 @@ logger.info ('info'); | ||
var append = function(more) { data.push(more) }; | ||
var logger = simplelog({level: 'warn', logger: append}); | ||
var logger = errorlog({level: 'warn', logger: append}); | ||
logger.debug('debug'); | ||
@@ -191,3 +191,3 @@ logger.info ('info'); | ||
var append = function(more) { data.push(more) }; | ||
var logger = simplelog({level: 'error', logger: append}); | ||
var logger = errorlog({level: 'error', logger: append}); | ||
logger.debug('debug'); | ||
@@ -204,3 +204,3 @@ logger.info ('info'); | ||
var append = function(more) { data.push(more) }; | ||
var logger = simplelog({level: 'off', logger: append}); | ||
var logger = errorlog({level: 'off', logger: append}); | ||
logger.debug('debug'); | ||
@@ -218,7 +218,7 @@ logger.info ('info'); | ||
var oldLevel = simplelog.defaultLevel; | ||
var oldLevel = errorlog.defaultLevel; | ||
try { | ||
simplelog.defaultLevel = simplelog.OFF; | ||
var logger = simplelog({logger: append}); | ||
errorlog.defaultLevel = errorlog.OFF; | ||
var logger = errorlog({logger: append}); | ||
@@ -228,3 +228,3 @@ logger('this should not show up'); | ||
simplelog.defaultLevel = simplelog.ALL; | ||
errorlog.defaultLevel = errorlog.ALL; | ||
logger('this must show up'); | ||
@@ -234,3 +234,3 @@ expect(data).to.eql([' LOG - this must show up']); | ||
} finally { | ||
simplelog.defaultLevel = oldLevel; | ||
errorlog.defaultLevel = oldLevel; | ||
} | ||
@@ -245,11 +245,11 @@ }) | ||
var oldLog = simplelog.defaultLog; | ||
var oldLog = errorlog.defaultLog; | ||
try { | ||
simplelog.defaultLog = append1; | ||
errorlog.defaultLog = append1; | ||
var logger = simplelog(); | ||
var logger = errorlog(); | ||
logger('logged to data 1'); | ||
simplelog.defaultLog = append2; | ||
errorlog.defaultLog = append2; | ||
@@ -262,7 +262,27 @@ logger('logged to data 2'); | ||
} finally { | ||
simplelog.defaultLog = oldLog; | ||
errorlog.defaultLog = oldLog; | ||
} | ||
}) | ||
it('should parse every level string', function() { | ||
errorlog.defaultLevel = 'ALL' ; | ||
expect(errorlog.defaultLevel).to.equal(-1); | ||
errorlog.defaultLevel = 'TRACE'; | ||
expect(errorlog.defaultLevel).to.equal(0); | ||
errorlog.defaultLevel = 'DEBUG'; | ||
expect(errorlog.defaultLevel).to.equal(100); | ||
errorlog.defaultLevel = 'INFO' ; | ||
expect(errorlog.defaultLevel).to.equal(200); | ||
errorlog.defaultLevel = 'WARN' ; | ||
expect(errorlog.defaultLevel).to.equal(300); | ||
errorlog.defaultLevel = 'ERROR'; | ||
expect(errorlog.defaultLevel).to.equal(400); | ||
errorlog.defaultLevel = 'FATAL'; | ||
expect(errorlog.defaultLevel).to.equal(500); | ||
errorlog.defaultLevel = 'OFF' ; | ||
expect(errorlog.defaultLevel).to.equal(Number.MAX_SAFE_INTEGER); | ||
}); | ||
}); | ||
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
24517
466