2014-11-06 175 views
1

溫斯頓記錄錯誤日誌幫我擺脫這種工作不正常

這是我的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 

回答

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

工作對我來說就像一個魅力。