Skip to content

Instantly share code, notes, and snippets.

@johndgiese
Last active May 6, 2019 09:09
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save johndgiese/59bd96360ce411042294 to your computer and use it in GitHub Desktop.
Save johndgiese/59bd96360ce411042294 to your computer and use it in GitHub Desktop.
Make node's winston logger print stack traces
// Extend a winston by making it expand errors when passed in as the
// second argument (the first argument is the log level).
function expandErrors(logger) {
var oldLogFunc = logger.log;
logger.log = function() {
var args = Array.prototype.slice.call(arguments, 0);
if (args.length >= 2 && args[1] instanceof Error) {
args[1] = args[1].stack;
}
return oldLogFunc.apply(this, args);
};
return logger;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment