Permalink
Browse files

Add prettyPrint option for files and console which uses util.inspect

  • Loading branch information...
1 parent 7169dd2 commit af8f96f18d8af77625d1c44149ddef3039bff8b2 @alFReD-NSH alFReD-NSH committed with jfhbrook Feb 29, 2012
Showing with 29 additions and 25 deletions.
  1. +1 −1 lib/winston/common.js
  2. +15 −13 lib/winston/transports/console.js
  3. +13 −11 lib/winston/transports/file.js
View
@@ -161,7 +161,7 @@ exports.log = function (options) {
output += ' ' + meta;
}
else if (Object.keys(meta).length > 0) {
- output += ' ' + exports.serialize(meta);
+ output += ' ' + (options.prettyPrint ? ('\n' + util.inspect(meta, false, null, options.colorize)) : exports.serialize(meta));
}
}
@@ -22,10 +22,11 @@ var Console = exports.Console = function (options) {
Transport.call(this, options);
options = options || {};
- this.name = 'console';
- this.json = options.json || false;
- this.colorize = options.colorize || false;
- this.timestamp = typeof options.timestamp !== 'undefined' ? options.timestamp : false;
+ this.name = 'console';
+ this.json = options.json || false;
+ this.colorize = options.colorize || false;
+ this.prettyPrint = options.prettyPrint || false;
+ this.timestamp = typeof options.timestamp !== 'undefined' ? options.timestamp : false;
if (this.json) {
this.stringify = options.stringify || function (obj) {
@@ -61,14 +62,15 @@ Console.prototype.log = function (level, msg, meta, callback) {
output;
output = common.log({
- colorize: this.colorize,
- json: this.json,
- level: level,
- message: msg,
- meta: meta,
- stringify: this.stringify,
- timestamp: this.timestamp,
- raw: this.raw
+ colorize: this.colorize,
+ json: this.json,
+ level: level,
+ message: msg,
+ meta: meta,
+ stringify: this.stringify,
+ timestamp: this.timestamp,
+ prettyPrint: this.prettyPrint,
+ raw: this.raw
});
if (level === 'error' || level === 'debug') {
@@ -83,4 +85,4 @@ Console.prototype.log = function (level, msg, meta, callback) {
//
self.emit('logged');
callback(null, true);
-};
+};
@@ -57,11 +57,12 @@ var File = exports.File = function (options) {
throw new Error('Cannot log to file without filename or stream.');
}
- this.json = options.json !== false;
- this.colorize = options.colorize || false;
- this.maxsize = options.maxsize || null;
- this.maxFiles = options.maxFiles || null;
- this.timestamp = options.timestamp != null ? options.timestamp : true;
+ this.json = options.json !== false;
+ this.colorize = options.colorize || false;
+ this.maxsize = options.maxsize || null;
+ this.maxFiles = options.maxFiles || null;
+ this.prettyPrint = options.prettyPrint || false;
+ this.timestamp = options.timestamp != null ? options.timestamp : true;
//
// Internal state variables representing the number
@@ -100,12 +101,13 @@ File.prototype.log = function (level, msg, meta, callback) {
var self = this;
var output = common.log({
- level: level,
- message: msg,
- meta: meta,
- json: this.json,
- colorize: this.colorize,
- timestamp: this.timestamp
+ level: level,
+ message: msg,
+ meta: meta,
+ json: this.json,
+ colorize: this.colorize,
+ prettyPrint: this.prettyPrint,
+ timestamp: this.timestamp
}) + '\n';
this._size += output.length;

0 comments on commit af8f96f

Please sign in to comment.