Skip to content

Commit

Permalink
[fix api] Expose json option passed in to winston.transports.Console
Browse files Browse the repository at this point in the history
  • Loading branch information
indexzero committed Sep 15, 2011
1 parent 7ef8c7e commit 1a3494a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 3 additions & 1 deletion lib/winston/common.js
Expand Up @@ -110,7 +110,9 @@ exports.log = function (options) {
output.timestamp = timestamp;
}

return JSON.stringify(output);
return typeof options.stringify === 'function'
? options.stringify(output)
: JSON.stringify(output);
}

output = timestamp ? timestamp + ' - ' : '';
Expand Down
10 changes: 9 additions & 1 deletion lib/winston/transports/console.js
Expand Up @@ -26,6 +26,12 @@ var Console = exports.Console = function (options) {
this.json = options.json || false;
this.colorize = options.colorize || false;
this.timestamp = typeof options.timestamp !== 'undefined' ? options.timestamp : false;

if (this.json) {
this.stringify = options.stringify || function (obj) {
return JSON.stringify(obj, null, 2);
};
}
};

//
Expand All @@ -52,10 +58,12 @@ Console.prototype.log = function (level, msg, meta, callback) {
}

var self = this, output = common.log({
colorize: this.colorize,
json: this.json,
level: level,
message: msg,
meta: meta,
colorize: this.colorize,
stringify: this.stringify,
timestamp: this.timestamp
});

Expand Down

0 comments on commit 1a3494a

Please sign in to comment.