diff --git a/CHANGES.md b/CHANGES.md index 16b5a1e..758736c 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -2,6 +2,15 @@ ## bunyan 0.6.3 (not yet released) +- Allow an optional `msg` and arguments to the `log.info( err)` logging + form. For example, before: + + log.debug(my_error_instance) // good + log.debug(my_error_instance, "boom!") // wasn't allowed + + Now the latter is allowed if you want to expliciting set the log msg. Of course + this applies to all the `log.{trace|debug|info...}()` methods. + - `bunyan` cli output: clarify extra fields with quoting if empty or have spaces. E.g. 'cmd' and 'stderr' in the following: diff --git a/lib/bunyan.js b/lib/bunyan.js index 01ae632..271c27c 100644 --- a/lib/bunyan.js +++ b/lib/bunyan.js @@ -657,7 +657,7 @@ Logger.prototype._emit = function (rec) { * * Usages: * log.trace() -> boolean is-trace-enabled - * log.trace( err) + * log.trace( err, [ msg, ...]) * log.trace( msg, ...) * log.trace( fields, msg, ...) * @@ -672,10 +672,14 @@ Logger.prototype.trace = function () { return (this.level <= TRACE); } else if (this.level > TRACE) { return; - } else if (arguments.length === 1 && arguments[0] instanceof Error) { - // `log.trace(err)` + } else if (arguments[0] instanceof Error) { + // `log.trace(err, ...)` fields = {err: errSerializer(arguments[0])}; - msgArgs = [fields.err.message]; + if (arguments.length === 1) { + msgArgs = [fields.err.message]; + } else { + msgArgs = Array.prototype.slice.call(arguments, 1); + } } else if (typeof arguments[0] === 'string') { // `log.trace(msg, ...)` fields = null; msgArgs = Array.prototype.slice.call(arguments); @@ -692,7 +696,7 @@ Logger.prototype.trace = function () { * * Usages: * log.debug() -> boolean is-debug-enabled - * log.debug( err) + * log.debug( err, [ msg, ...]) * log.debug( msg, ...) * log.debug( fields, msg, ...) * @@ -707,10 +711,14 @@ Logger.prototype.debug = function () { return (this.level <= DEBUG); } else if (this.level > DEBUG) { return; - } else if (arguments.length === 1 && arguments[0] instanceof Error) { - // `log.debug(err)` + } else if (arguments[0] instanceof Error) { + // `log.debug(err, ...)` fields = {err: errSerializer(arguments[0])}; - msgArgs = [fields.err.message]; + if (arguments.length === 1) { + msgArgs = [fields.err.message]; + } else { + msgArgs = Array.prototype.slice.call(arguments, 1); + } } else if (typeof arguments[0] === 'string') { // `log.debug(msg, ...)` fields = null; msgArgs = Array.prototype.slice.call(arguments); @@ -727,7 +735,7 @@ Logger.prototype.debug = function () { * * Usages: * log.info() -> boolean is-info-enabled - * log.info( err) + * log.info( err, [ msg, ...]) * log.info( msg, ...) * log.info( fields, msg, ...) * @@ -742,10 +750,14 @@ Logger.prototype.info = function () { return (this.level <= INFO); } else if (this.level > INFO) { return; - } else if (arguments.length === 1 && arguments[0] instanceof Error) { - // `log.info(err)` + } else if (arguments[0] instanceof Error) { + // `log.info(err, ...)` fields = {err: errSerializer(arguments[0])}; - msgArgs = [fields.err.message]; + if (arguments.length === 1) { + msgArgs = [fields.err.message]; + } else { + msgArgs = Array.prototype.slice.call(arguments, 1); + } } else if (typeof arguments[0] === 'string') { // `log.info(msg, ...)` fields = null; msgArgs = Array.prototype.slice.call(arguments); @@ -762,7 +774,7 @@ Logger.prototype.info = function () { * * Usages: * log.warn() -> boolean is-warn-enabled - * log.warn( err) + * log.warn( err, [ msg, ...]) * log.warn( msg, ...) * log.warn( fields, msg, ...) * @@ -777,10 +789,14 @@ Logger.prototype.warn = function () { return (this.level <= WARN); } else if (this.level > WARN) { return; - } else if (arguments.length === 1 && arguments[0] instanceof Error) { - // `log.warn(err)` + } else if (arguments[0] instanceof Error) { + // `log.warn(err, ...)` fields = {err: errSerializer(arguments[0])}; - msgArgs = [fields.err.message]; + if (arguments.length === 1) { + msgArgs = [fields.err.message]; + } else { + msgArgs = Array.prototype.slice.call(arguments, 1); + } } else if (typeof arguments[0] === 'string') { // `log.warn(msg, ...)` fields = null; msgArgs = Array.prototype.slice.call(arguments); @@ -797,7 +813,7 @@ Logger.prototype.warn = function () { * * Usages: * log.error() -> boolean is-error-enabled - * log.error( err) + * log.error( err, [ msg, ...]) * log.error( msg, ...) * log.error( fields, msg, ...) * @@ -812,10 +828,14 @@ Logger.prototype.error = function () { return (this.level <= ERROR); } else if (this.level > ERROR) { return; - } else if (arguments.length === 1 && arguments[0] instanceof Error) { - // `log.error(err)` + } else if (arguments[0] instanceof Error) { + // `log.error(err, ...)` fields = {err: errSerializer(arguments[0])}; - msgArgs = [fields.err.message]; + if (arguments.length === 1) { + msgArgs = [fields.err.message]; + } else { + msgArgs = Array.prototype.slice.call(arguments, 1); + } } else if (typeof arguments[0] === 'string') { // `log.error(msg, ...)` fields = null; msgArgs = Array.prototype.slice.call(arguments); @@ -832,7 +852,7 @@ Logger.prototype.error = function () { * * Usages: * log.fatal() -> boolean is-fatal-enabled - * log.fatal( err) + * log.fatal( err, [ msg, ...]) * log.fatal( msg, ...) * log.fatal( fields, msg, ...) * @@ -847,10 +867,14 @@ Logger.prototype.fatal = function () { return (this.level <= FATAL); } else if (this.level > FATAL) { return; - } else if (arguments.length === 1 && arguments[0] instanceof Error) { - // `log.fatal(err)` + } else if (arguments[0] instanceof Error) { + // `log.fatal(err, ...)` fields = {err: errSerializer(arguments[0])}; - msgArgs = [fields.err.message]; + if (arguments.length === 1) { + msgArgs = [fields.err.message]; + } else { + msgArgs = Array.prototype.slice.call(arguments, 1); + } } else if (typeof arguments[0] === 'string') { // `log.fatal(msg, ...)` fields = null; msgArgs = Array.prototype.slice.call(arguments);