【发布时间】:2021-12-31 11:42:46
【问题描述】:
只有一种传输方式,添加如下:
winston.add(winston.createLogger({
transports: [
new winston.transports.Console({
handleExceptions: true,
format: winston.format.combine(
winston.format.simple()
),
}),
]
}));
当index.js 抛出新错误时:throw new Error('++++ I will log twice ++++')
将产生两个单独的日志!
我也尝试过transport.File({ ... }),但结果相同。
更新: 正如@terry-lennox 在他的answer 中提到的那样,输出类似于:
error: uncaughtException: ++++ I will log twice ++++
Error: ++++ I will log twice ++++
at Object.
at Module._compile (internal/modules/cjs/loader.js:689:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
at Module.load (internal/modules/cjs/loader.js:599:32)
error: uncaughtException: ++++ I will log twice ++++
Error: ++++ I will log twice ++++
at Object.
at Module._compile (internal/modules/cjs/loader.js:689:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
at Module.load (internal/modules/cjs/loader.js:599:32)
系统设置版本:
OS: Windows 10 v1803
NodeJS: 10.14.1
express: 4.16.4
winston: 3.2.1
【问题讨论】: