winston logger错误记录无法正常工作

时间:2014-11-06 17:18:12

标签: winston

帮助我摆脱这个

这是我的console.log

的输出
{ [error: column "hello" does not exist]
name: 'error',
length: 119,
severity: 'ERROR',
code: '42703',
detail: undefined,
hint: undefined,
position: '1271',
internalPosition: undefined,
internalQuery: undefined,
where: undefined,
file: 'src\backend\parser\parse_relation.c',
line: '2655',enter code here
routine: 'errorMissingColumn' }

这是我的logger.error

的输出
error: name=error, length=119, severity=ERROR, code=42703, detail=undefined, hi
nt=undefined, position=1271, internalPosition=undefined, internalQuery=undefined
, where=undefined, file=src\backend\parser\parse_relation.c, line=2655, routine=
errorMissingColumn

console.log is more understandable and clear ,but logger.error message is not clear understand

1 个答案:

答案 0 :(得分:0)

我在这里发现了这个问题(我不是作者)

https://gist.github.com/johndgiese/59bd96360ce411042294

// 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;
}

为我工作就像一个魅力。