info's sibling APIs

This commit is contained in:
Trent Mick 2012-01-30 12:40:57 -08:00
parent 99ecaf2845
commit 6d94985f2d
3 changed files with 133 additions and 4 deletions

View file

@ -1,4 +1,6 @@
- info's siblings
- mark wants pretty output for debug output
- not sure if 'bunyan --pretty' or whatever would suffice
- mark suggested a list of streams. This is what ring could be.
- `bunyan` cli
- expand set of fields
<https://github.com/Graylog2/graylog2-docs/wiki/GELF>

2
hi.js
View file

@ -16,7 +16,7 @@ function Wuzzle(options) {
}
Wuzzle.prototype.woos = function () {
this.log.info("This wuzzle is woosey.")
this.log.warn("This wuzzle is woosey.")
}
var wuzzle = new Wuzzle({log: log.clone({component: "wuzzle"})});

View file

@ -204,10 +204,47 @@ Logger.prototype._emit = function (rec) {
/**
* Log a record at DEBUG level.
*
* Usages:
* log.debug() -> boolean is-debug-enabled
* log.debug(<string> msg, ...)
* log.debug(<object> fields, <string> msg, ...)
*
* @params fields {Object} Optional set of additional fields to log.
* @params msg {String} Log message. This can be followed by additional
* arguments that are handled like
* [util.format](http://nodejs.org/docs/latest/api/all.html#util.format).
*/
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;
} else if (typeof arguments[0] === 'string') { // `log.debug(msg, ...)`
fields = null;
msgArgs = Array.prototype.slice.call(arguments);
} else { // `log.debug(fields, msg, ...)`
fields = arguments[0];
msgArgs = Array.prototype.slice.call(arguments, 1);
}
var rec = this._mkRecord(fields, DEBUG, msgArgs);
this._emit(rec);
}
/**
* Log a record at INFO level.
*
* Usages:
* log.info(<object> fields, <string> msg, ...)
* log.info(<string> msg, ...)
* log.info() -> boolean is-info-enabled
* log.info(<string> msg, ...)
* log.info(<object> fields, <string> msg, ...)
*
* @params fields {Object} Optional set of additional fields to log.
* @params msg {String} Log message. This can be followed by additional
* arguments that are handled like
* [util.format](http://nodejs.org/docs/latest/api/all.html#util.format).
*/
Logger.prototype.info = function () {
var fields = null, msgArgs = null;
@ -226,6 +263,96 @@ Logger.prototype.info = function () {
this._emit(rec);
}
/**
* Log a record at WARN level.
*
* Usages:
* log.warn() -> boolean is-warn-enabled
* log.warn(<string> msg, ...)
* log.warn(<object> fields, <string> msg, ...)
*
* @params fields {Object} Optional set of additional fields to log.
* @params msg {String} Log message. This can be followed by additional
* arguments that are handled like
* [util.format](http://nodejs.org/docs/latest/api/all.html#util.format).
*/
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;
} else if (typeof arguments[0] === 'string') { // `log.warn(msg, ...)`
fields = null;
msgArgs = Array.prototype.slice.call(arguments);
} else { // `log.warn(fields, msg, ...)`
fields = arguments[0];
msgArgs = Array.prototype.slice.call(arguments, 1);
}
var rec = this._mkRecord(fields, WARN, msgArgs);
this._emit(rec);
}
/**
* Log a record at ERROR level.
*
* Usages:
* log.error() -> boolean is-error-enabled
* log.error(<string> msg, ...)
* log.error(<object> fields, <string> msg, ...)
*
* @params fields {Object} Optional set of additional fields to log.
* @params msg {String} Log message. This can be followed by additional
* arguments that are handled like
* [util.format](http://nodejs.org/docs/latest/api/all.html#util.format).
*/
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;
} else if (typeof arguments[0] === 'string') { // `log.error(msg, ...)`
fields = null;
msgArgs = Array.prototype.slice.call(arguments);
} else { // `log.error(fields, msg, ...)`
fields = arguments[0];
msgArgs = Array.prototype.slice.call(arguments, 1);
}
var rec = this._mkRecord(fields, ERROR, msgArgs);
this._emit(rec);
}
/**
* Log a record at FATAL level.
*
* Usages:
* log.fatal() -> boolean is-fatal-enabled
* log.fatal(<string> msg, ...)
* log.fatal(<object> fields, <string> msg, ...)
*
* @params fields {Object} Optional set of additional fields to log.
* @params msg {String} Log message. This can be followed by additional
* arguments that are handled like
* [util.format](http://nodejs.org/docs/latest/api/all.html#util.format).
*/
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;
} else if (typeof arguments[0] === 'string') { // `log.fatal(msg, ...)`
fields = null;
msgArgs = Array.prototype.slice.call(arguments);
} else { // `log.fatal(fields, msg, ...)`
fields = arguments[0];
msgArgs = Array.prototype.slice.call(arguments, 1);
}
var rec = this._mkRecord(fields, FATAL, msgArgs);
this._emit(rec);
}
module.exports = Logger;