Skip to content

Commit 50163a0

Browse files
samzilverbergindexzero
authored andcommitted
nice print of unhandled exception stack trace
1 parent 359c524 commit 50163a0

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

lib/winston/common.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,8 +223,26 @@ exports.log = function (options) {
223223
output += ' ' + options.prettyPrint(meta);
224224
} else if (options.prettyPrint) {
225225
output += ' ' + '\n' + util.inspect(meta, false, options.depth || null, options.colorize);
226-
} else {
226+
} else if (
227+
Object.keys(meta).length === 5
228+
&& meta.hasOwnProperty('date')
229+
&& meta.hasOwnProperty('process')
230+
&& meta.hasOwnProperty('os')
231+
&& meta.hasOwnProperty('trace')
232+
&& meta.hasOwnProperty('stack')) {
233+
234+
//
235+
// If meta carries unhandled exception data serialize the stack nicely
236+
//
237+
var stack = meta.stack;
238+
delete meta.stack;
239+
delete meta.trace;
227240
output += ' ' + exports.serialize(meta);
241+
output += '\n' + stack.map(function(s){
242+
return s + '\n';
243+
});
244+
} else {
245+
output += ' ' + exports.serialize(meta);
228246
}
229247
}
230248
}

0 commit comments

Comments
 (0)