Skip to content

Commit

Permalink
Add prettyPrint option for files and console which uses util.inspect
Browse files Browse the repository at this point in the history
  • Loading branch information
faridnsh authored and jfhbrook committed Jun 13, 2012
1 parent 7169dd2 commit af8f96f
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 25 deletions.
2 changes: 1 addition & 1 deletion lib/winston/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}

Expand Down
28 changes: 15 additions & 13 deletions lib/winston/transports/console.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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') {
Expand All @@ -83,4 +85,4 @@ Console.prototype.log = function (level, msg, meta, callback) {
//
self.emit('logged');
callback(null, true);
};
};
24 changes: 13 additions & 11 deletions lib/winston/transports/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit af8f96f

Please sign in to comment.