diff --git a/lib/winston/common.js b/lib/winston/common.js index 6dd6b7d43..7b57fca10 100644 --- a/lib/winston/common.js +++ b/lib/winston/common.js @@ -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 + ' - ' : ''; diff --git a/lib/winston/transports/console.js b/lib/winston/transports/console.js index 5e31fb2e8..b38ef04e5 100644 --- a/lib/winston/transports/console.js +++ b/lib/winston/transports/console.js @@ -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); + }; + } }; // @@ -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 });