【发布时间】:2019-01-25 17:11:59
【问题描述】:
我有一个节点应用程序,我在其中使用Winstonjs 作为记录器。在我的记录器中,我有一个特定的部分用于记录这样的异常:
const myFormat = winston.format.printf(info => {
return `${info.timestamp} ${info.level}: ${info.message}`;
});
const logger = winston.createLogger({
level: "debug",
format: winston.format.combine(winston.format.timestamp(), myFormat), // winston.format.json(),
transports: [
new winston.transports.File({filename: "logs/error.log", level: 'error'}),
new winston.transports.File({filename: 'logs/combined.log'}),
],
exceptionHandlers: [
new winston.transports.File({ filename: 'logs/exceptions.log' }),
new winston.transports.File({ filename: 'logs/combined.log' })
],
exitOnError: false
});
所以任何异常都应该记录在logs/combined.log 和logs/exceptions.log 中。
当我运行我的程序时,我现在有时会在我的 STDOUT 中收到以下错误,该错误来自我用来写入我的 MySQL 数据库的Sequelizejs。
Unhandled rejection TimeoutError: ResourceRequest timed out
at ResourceRequest._fireTimeout (/root/mmjs/node_modules/generic-pool/lib/ResourceRequest.js:62:17)
at Timeout.bound (/root/mmjs/node_modules/generic-pool/lib/ResourceRequest.js:8:15)
at ontimeout (timers.js:424:11)
at tryOnTimeout (timers.js:288:5)
at listOnTimeout (timers.js:251:5)
at Timer.processTimers (timers.js:211:10)
这个错误只出现在标准输出中(当手动运行我的程序时),它不会出现在combined.log 或exceptions.log 中。这可能是因为这是一个错误而不是异常。不过,我不确定如何正确记录。
(我想我可以wrap my whole code in a try/catch,但我想还有更好的方法.. :-))
谁能帮我记录这个和类似的未捕获的错误?
【问题讨论】:
-
所以你的nodejs程序被那个错误杀死了?什么在运行你的 nodejs 程序?下午2点?
-
@Cétia - 目前我只是手动运行它:
node index.js
标签: javascript node.js logging error-handling winston