2017-09-06 76 views
1

使用winston記錄器將內容寫入文件,但僅在使用customlogger.error時才起作用。如果節點正在輸出一些像下面的參考錯誤如何輸出process.stderr.write到winston

ReferenceError: aksbd is not defined 
at /home/nigilan/Desktop/homepagelogger/app.js:53:20 
at Layer.handle [as handle_request] (/home/nigilan/Desktop/homepagelogger/node_modules/express/lib/router/layer.js:95:5) 
at next (/home/nigilan/Desktop/homepagelogger/node_modules/express/lib/router/route.js:137:13) 
at Route.dispatch (/home/nigilan/Desktop/homepagelogger/node_modules/express/lib/router/route.js:112:3) 
at Layer.handle [as handle_request] (/home/nigilan/Desktop/homepagelogger/node_modules/express/lib/router/layer.js:95:5) 
at /home/nigilan/Desktop/homepagelogger/node_modules/express/lib/router/index.js:281:22 
at Function.process_params (/home/nigilan/Desktop/homepagelogger/node_modules/express/lib/router/index.js:335:12) 
at next (/home/nigilan/Desktop/homepagelogger/node_modules/express/lib/router/index.js:275:10) 
at /home/nigilan/Desktop/homepagelogger/app.js:38:5 
at Layer.handle [as handle_request] (/home/nigilan/Desktop/homepagelogger/node_modules/express/lib/router/layer.js:95:5) 

如何使用Winston存儲類似上面的錯誤?

P.S.記錄未處理的異常是nodejs服務器工作正常。

+0

此代碼工作正常,但溫斯頓會非常有幫助。 (err)throw err; });函數(message){0}; } – Nigilan

回答

0
` 
function formatArgs(args){ 
    return [util.format.apply(util.format, Array.prototype.slice.call(args))]; 
} 
console.info = function(){ 
    customlogger.info.apply(customlogger, formatArgs(arguments)); 
}; 
console.warn = function(){ 
    customlogger.warn.apply(customlogger, formatArgs(arguments)); 
};` 

在這裏,您還可以使用winston的默認記錄器而不是您的自定義記錄器。下面的要點代碼對於this有完美的答案。