Allow an optional msg and arguments to the log.info(<Error> err) logging form.

This commit is contained in:
Trent Mick 2012-02-16 16:49:19 -08:00
parent 61ff4030e4
commit 519f263ad1
2 changed files with 57 additions and 24 deletions

View file

@ -2,6 +2,15 @@
## bunyan 0.6.3 (not yet released) ## bunyan 0.6.3 (not yet released)
- Allow an optional `msg` and arguments to the `log.info(<Error> 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 - `bunyan` cli output: clarify extra fields with quoting if empty or have
spaces. E.g. 'cmd' and 'stderr' in the following: spaces. E.g. 'cmd' and 'stderr' in the following:

View file

@ -657,7 +657,7 @@ Logger.prototype._emit = function (rec) {
* *
* Usages: * Usages:
* log.trace() -> boolean is-trace-enabled * log.trace() -> boolean is-trace-enabled
* log.trace(<Error> err) * log.trace(<Error> err, [<string> msg, ...])
* log.trace(<string> msg, ...) * log.trace(<string> msg, ...)
* log.trace(<object> fields, <string> msg, ...) * log.trace(<object> fields, <string> msg, ...)
* *
@ -672,10 +672,14 @@ Logger.prototype.trace = function () {
return (this.level <= TRACE); return (this.level <= TRACE);
} else if (this.level > TRACE) { } else if (this.level > TRACE) {
return; return;
} else if (arguments.length === 1 && arguments[0] instanceof Error) { } else if (arguments[0] instanceof Error) {
// `log.trace(err)` // `log.trace(err, ...)`
fields = {err: errSerializer(arguments[0])}; 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, ...)` } else if (typeof arguments[0] === 'string') { // `log.trace(msg, ...)`
fields = null; fields = null;
msgArgs = Array.prototype.slice.call(arguments); msgArgs = Array.prototype.slice.call(arguments);
@ -692,7 +696,7 @@ Logger.prototype.trace = function () {
* *
* Usages: * Usages:
* log.debug() -> boolean is-debug-enabled * log.debug() -> boolean is-debug-enabled
* log.debug(<Error> err) * log.debug(<Error> err, [<string> msg, ...])
* log.debug(<string> msg, ...) * log.debug(<string> msg, ...)
* log.debug(<object> fields, <string> msg, ...) * log.debug(<object> fields, <string> msg, ...)
* *
@ -707,10 +711,14 @@ Logger.prototype.debug = function () {
return (this.level <= DEBUG); return (this.level <= DEBUG);
} else if (this.level > DEBUG) { } else if (this.level > DEBUG) {
return; return;
} else if (arguments.length === 1 && arguments[0] instanceof Error) { } else if (arguments[0] instanceof Error) {
// `log.debug(err)` // `log.debug(err, ...)`
fields = {err: errSerializer(arguments[0])}; 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, ...)` } else if (typeof arguments[0] === 'string') { // `log.debug(msg, ...)`
fields = null; fields = null;
msgArgs = Array.prototype.slice.call(arguments); msgArgs = Array.prototype.slice.call(arguments);
@ -727,7 +735,7 @@ Logger.prototype.debug = function () {
* *
* Usages: * Usages:
* log.info() -> boolean is-info-enabled * log.info() -> boolean is-info-enabled
* log.info(<Error> err) * log.info(<Error> err, [<string> msg, ...])
* log.info(<string> msg, ...) * log.info(<string> msg, ...)
* log.info(<object> fields, <string> msg, ...) * log.info(<object> fields, <string> msg, ...)
* *
@ -742,10 +750,14 @@ Logger.prototype.info = function () {
return (this.level <= INFO); return (this.level <= INFO);
} else if (this.level > INFO) { } else if (this.level > INFO) {
return; return;
} else if (arguments.length === 1 && arguments[0] instanceof Error) { } else if (arguments[0] instanceof Error) {
// `log.info(err)` // `log.info(err, ...)`
fields = {err: errSerializer(arguments[0])}; 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, ...)` } else if (typeof arguments[0] === 'string') { // `log.info(msg, ...)`
fields = null; fields = null;
msgArgs = Array.prototype.slice.call(arguments); msgArgs = Array.prototype.slice.call(arguments);
@ -762,7 +774,7 @@ Logger.prototype.info = function () {
* *
* Usages: * Usages:
* log.warn() -> boolean is-warn-enabled * log.warn() -> boolean is-warn-enabled
* log.warn(<Error> err) * log.warn(<Error> err, [<string> msg, ...])
* log.warn(<string> msg, ...) * log.warn(<string> msg, ...)
* log.warn(<object> fields, <string> msg, ...) * log.warn(<object> fields, <string> msg, ...)
* *
@ -777,10 +789,14 @@ Logger.prototype.warn = function () {
return (this.level <= WARN); return (this.level <= WARN);
} else if (this.level > WARN) { } else if (this.level > WARN) {
return; return;
} else if (arguments.length === 1 && arguments[0] instanceof Error) { } else if (arguments[0] instanceof Error) {
// `log.warn(err)` // `log.warn(err, ...)`
fields = {err: errSerializer(arguments[0])}; 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, ...)` } else if (typeof arguments[0] === 'string') { // `log.warn(msg, ...)`
fields = null; fields = null;
msgArgs = Array.prototype.slice.call(arguments); msgArgs = Array.prototype.slice.call(arguments);
@ -797,7 +813,7 @@ Logger.prototype.warn = function () {
* *
* Usages: * Usages:
* log.error() -> boolean is-error-enabled * log.error() -> boolean is-error-enabled
* log.error(<Error> err) * log.error(<Error> err, [<string> msg, ...])
* log.error(<string> msg, ...) * log.error(<string> msg, ...)
* log.error(<object> fields, <string> msg, ...) * log.error(<object> fields, <string> msg, ...)
* *
@ -812,10 +828,14 @@ Logger.prototype.error = function () {
return (this.level <= ERROR); return (this.level <= ERROR);
} else if (this.level > ERROR) { } else if (this.level > ERROR) {
return; return;
} else if (arguments.length === 1 && arguments[0] instanceof Error) { } else if (arguments[0] instanceof Error) {
// `log.error(err)` // `log.error(err, ...)`
fields = {err: errSerializer(arguments[0])}; 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, ...)` } else if (typeof arguments[0] === 'string') { // `log.error(msg, ...)`
fields = null; fields = null;
msgArgs = Array.prototype.slice.call(arguments); msgArgs = Array.prototype.slice.call(arguments);
@ -832,7 +852,7 @@ Logger.prototype.error = function () {
* *
* Usages: * Usages:
* log.fatal() -> boolean is-fatal-enabled * log.fatal() -> boolean is-fatal-enabled
* log.fatal(<Error> err) * log.fatal(<Error> err, [<string> msg, ...])
* log.fatal(<string> msg, ...) * log.fatal(<string> msg, ...)
* log.fatal(<object> fields, <string> msg, ...) * log.fatal(<object> fields, <string> msg, ...)
* *
@ -847,10 +867,14 @@ Logger.prototype.fatal = function () {
return (this.level <= FATAL); return (this.level <= FATAL);
} else if (this.level > FATAL) { } else if (this.level > FATAL) {
return; return;
} else if (arguments.length === 1 && arguments[0] instanceof Error) { } else if (arguments[0] instanceof Error) {
// `log.fatal(err)` // `log.fatal(err, ...)`
fields = {err: errSerializer(arguments[0])}; 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, ...)` } else if (typeof arguments[0] === 'string') { // `log.fatal(msg, ...)`
fields = null; fields = null;
msgArgs = Array.prototype.slice.call(arguments); msgArgs = Array.prototype.slice.call(arguments);