From 40ec83b6216726c34db1aa7b5ebbda32e62b60d7 Mon Sep 17 00:00:00 2001 From: Trent Mick Date: Sun, 19 Feb 2012 21:42:23 -0800 Subject: [PATCH] [issue #5] Fix `log.info() -> boolean` to work properly. Previous all were returning false. Ditto all trace/debug/.../fatal methods. --- CHANGES.md | 6 ++++++ lib/bunyan.js | 24 +++++++++++----------- test/log.test.js | 53 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 71 insertions(+), 12 deletions(-) create mode 100644 test/log.test.js diff --git a/CHANGES.md b/CHANGES.md index e04d62f..2594641 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,11 @@ # 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 - Allow an optional `msg` and arguments to the `log.info( err)` logging diff --git a/lib/bunyan.js b/lib/bunyan.js index af8794a..33a924c 100644 --- a/lib/bunyan.js +++ b/lib/bunyan.js @@ -669,8 +669,8 @@ Logger.prototype._emit = function (rec) { Logger.prototype.trace = function () { var fields = null, msgArgs = null; if (arguments.length === 0) { // `log.trace()` - return (this.level <= TRACE); - } else if (this.level > TRACE) { + return (this._level <= TRACE); + } else if (this._level > TRACE) { return; } else if (arguments[0] instanceof Error) { // `log.trace(err, ...)` @@ -708,8 +708,8 @@ Logger.prototype.trace = function () { Logger.prototype.debug = function () { var fields = null, msgArgs = null; if (arguments.length === 0) { // `log.debug()` - return (this.level <= DEBUG); - } else if (this.level > DEBUG) { + return (this._level <= DEBUG); + } else if (this._level > DEBUG) { return; } else if (arguments[0] instanceof Error) { // `log.debug(err, ...)` @@ -747,8 +747,8 @@ Logger.prototype.debug = function () { Logger.prototype.info = function () { var fields = null, msgArgs = null; if (arguments.length === 0) { // `log.info()` - return (this.level <= INFO); - } else if (this.level > INFO) { + return (this._level <= INFO); + } else if (this._level > INFO) { return; } else if (arguments[0] instanceof Error) { // `log.info(err, ...)` @@ -786,8 +786,8 @@ Logger.prototype.info = function () { Logger.prototype.warn = function () { var fields = null, msgArgs = null; if (arguments.length === 0) { // `log.warn()` - return (this.level <= WARN); - } else if (this.level > WARN) { + return (this._level <= WARN); + } else if (this._level > WARN) { return; } else if (arguments[0] instanceof Error) { // `log.warn(err, ...)` @@ -825,8 +825,8 @@ Logger.prototype.warn = function () { Logger.prototype.error = function () { var fields = null, msgArgs = null; if (arguments.length === 0) { // `log.error()` - return (this.level <= ERROR); - } else if (this.level > ERROR) { + return (this._level <= ERROR); + } else if (this._level > ERROR) { return; } else if (arguments[0] instanceof Error) { // `log.error(err, ...)` @@ -864,8 +864,8 @@ Logger.prototype.error = function () { Logger.prototype.fatal = function () { var fields = null, msgArgs = null; if (arguments.length === 0) { // `log.fatal()` - return (this.level <= FATAL); - } else if (this.level > FATAL) { + return (this._level <= FATAL); + } else if (this._level > FATAL) { return; } else if (arguments[0] instanceof Error) { // `log.fatal(err, ...)` diff --git a/test/log.test.js b/test/log.test.js new file mode 100644 index 0000000..264d946 --- /dev/null +++ b/test/log.test.js @@ -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