[issue #5] Fix log.info() -> boolean to work properly. Previous all were returning false.

Ditto all trace/debug/.../fatal methods.
This commit is contained in:
Trent Mick 2012-02-19 21:42:23 -08:00
parent 0d713a46d8
commit 40ec83b621
3 changed files with 71 additions and 12 deletions

View file

@ -1,5 +1,11 @@
# bunyan Changelog # bunyan Changelog
## bunyan 0.6.4 (not yet released)
- [issue #5] Fix `log.info() -> boolean` to work properly. Previous all were
returning false. Ditto all trace/debug/.../fatal methods.
## bunyan 0.6.3 ## bunyan 0.6.3
- Allow an optional `msg` and arguments to the `log.info(<Error> err)` logging - Allow an optional `msg` and arguments to the `log.info(<Error> err)` logging

View file

@ -669,8 +669,8 @@ Logger.prototype._emit = function (rec) {
Logger.prototype.trace = function () { Logger.prototype.trace = function () {
var fields = null, msgArgs = null; var fields = null, msgArgs = null;
if (arguments.length === 0) { // `log.trace()` if (arguments.length === 0) { // `log.trace()`
return (this.level <= TRACE); return (this._level <= TRACE);
} else if (this.level > TRACE) { } else if (this._level > TRACE) {
return; return;
} else if (arguments[0] instanceof Error) { } else if (arguments[0] instanceof Error) {
// `log.trace(err, ...)` // `log.trace(err, ...)`
@ -708,8 +708,8 @@ Logger.prototype.trace = function () {
Logger.prototype.debug = function () { Logger.prototype.debug = function () {
var fields = null, msgArgs = null; var fields = null, msgArgs = null;
if (arguments.length === 0) { // `log.debug()` if (arguments.length === 0) { // `log.debug()`
return (this.level <= DEBUG); return (this._level <= DEBUG);
} else if (this.level > DEBUG) { } else if (this._level > DEBUG) {
return; return;
} else if (arguments[0] instanceof Error) { } else if (arguments[0] instanceof Error) {
// `log.debug(err, ...)` // `log.debug(err, ...)`
@ -747,8 +747,8 @@ Logger.prototype.debug = function () {
Logger.prototype.info = function () { Logger.prototype.info = function () {
var fields = null, msgArgs = null; var fields = null, msgArgs = null;
if (arguments.length === 0) { // `log.info()` if (arguments.length === 0) { // `log.info()`
return (this.level <= INFO); return (this._level <= INFO);
} else if (this.level > INFO) { } else if (this._level > INFO) {
return; return;
} else if (arguments[0] instanceof Error) { } else if (arguments[0] instanceof Error) {
// `log.info(err, ...)` // `log.info(err, ...)`
@ -786,8 +786,8 @@ Logger.prototype.info = function () {
Logger.prototype.warn = function () { Logger.prototype.warn = function () {
var fields = null, msgArgs = null; var fields = null, msgArgs = null;
if (arguments.length === 0) { // `log.warn()` if (arguments.length === 0) { // `log.warn()`
return (this.level <= WARN); return (this._level <= WARN);
} else if (this.level > WARN) { } else if (this._level > WARN) {
return; return;
} else if (arguments[0] instanceof Error) { } else if (arguments[0] instanceof Error) {
// `log.warn(err, ...)` // `log.warn(err, ...)`
@ -825,8 +825,8 @@ Logger.prototype.warn = function () {
Logger.prototype.error = function () { Logger.prototype.error = function () {
var fields = null, msgArgs = null; var fields = null, msgArgs = null;
if (arguments.length === 0) { // `log.error()` if (arguments.length === 0) { // `log.error()`
return (this.level <= ERROR); return (this._level <= ERROR);
} else if (this.level > ERROR) { } else if (this._level > ERROR) {
return; return;
} else if (arguments[0] instanceof Error) { } else if (arguments[0] instanceof Error) {
// `log.error(err, ...)` // `log.error(err, ...)`
@ -864,8 +864,8 @@ Logger.prototype.error = function () {
Logger.prototype.fatal = function () { Logger.prototype.fatal = function () {
var fields = null, msgArgs = null; var fields = null, msgArgs = null;
if (arguments.length === 0) { // `log.fatal()` if (arguments.length === 0) { // `log.fatal()`
return (this.level <= FATAL); return (this._level <= FATAL);
} else if (this.level > FATAL) { } else if (this._level > FATAL) {
return; return;
} else if (arguments[0] instanceof Error) { } else if (arguments[0] instanceof Error) {
// `log.fatal(err, ...)` // `log.fatal(err, ...)`

53
test/log.test.js Normal file
View file

@ -0,0 +1,53 @@
/*
* Copyright (c) 2012 Trent Mick. All rights reserved.
*
* Test the `log.trace(...)`, `log.debug(...)`, ..., `log.fatal(...)` API.
*/
var test = require('tap').test;
var Logger = require('../lib/bunyan');
var log1 = new Logger({
name: 'log1',
streams: [
{
path: __dirname + '/log.test.log1.log',
level: 'info'
}
]
});
var log2 = new Logger({
name: 'log2',
streams: [
{
path: __dirname + '/log.test.log2a.log',
level: 'error'
},
{
path: __dirname + '/log.test.log2b.log',
level: 'debug'
}
]
})
test('log.LEVEL() -> boolean', function (t) {
t.equal(log1.trace(), false)
t.equal(log1.debug(), false)
t.equal(log1.info(), true)
t.equal(log1.warn(), true)
t.equal(log1.error(), true)
t.equal(log1.fatal(), true)
// Level is the *lowest* level of all streams.
t.equal(log2.trace(), false)
t.equal(log2.debug(), true)
t.equal(log2.info(), true)
t.equal(log2.warn(), true)
t.equal(log2.error(), true)
t.equal(log2.fatal(), true)
t.end();
});
//TODO:
// - rest of api