只有一种运输方式,像这样添加:
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
答案 0 :(得分:0)
您所看到的是这种行为吗?
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)
还是您看到这种情况重复出现?