在使用带有winston-daily-rotate-file软件包的文件日志记录时,在winston中出现以下错误,代码在Winston控制台日志记录中很好地工作,
MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 error listeners added. Use emitter.setMaxListeners() to increase limit
at _addListener (events.js:256:17)
at DailyRotateFile.addListener (events.js:272:10)
at DailyRotateFile.once (events.js:301:8)
at asyncForEach (/home/ubuntumachine/Desktop/project/node_modules/winston/lib/winston/exception-handler.js:217:17)
at /home/ubuntumachine/Desktop/project/node_modules/async/internal/withoutIndex.js:9:16
at eachOfArrayLike (/home/ubuntumachine/Desktop/project/node_modules/async/eachOf.js:65:9)
at exports.default (/home/ubuntumachine/Desktop/project/node_modules/async/eachOf.js:9:5)
at eachLimit (/home/ubuntumachine/Desktop/project/node_modules/async/forEach.js:80:24)
at ExceptionHandler._uncaughtException (/home/ubuntumachine/Desktop/project/node_modules/winston/lib/winston/exception-handler.js:203:5)
at process.emit (events.js:198:13)
(node:20805) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 finish listeners added. Use emitter.setMaxListeners() to increase limit
at _addListener (events.js:256:17)
at DailyRotateFile.addListener (events.js:272:10)
at DailyRotateFile.once (events.js:301:8)
at asyncForEach (/home/ubuntumachine/Desktop/project/node_modules/winston/lib/winston/exception-handler.js:216:17)
at /home/ubuntumachine/Desktop/project/node_modules/async/internal/withoutIndex.js:9:16
at eachOfArrayLike (/home/ubuntumachine/Desktop/project/node_modules/async/eachOf.js:65:9)
at exports.default (/home/ubuntumachine/Desktop/project/node_modules/async/eachOf.js:9:5)
at eachLimit (/home/ubuntumachine/Desktop/project/node_modules/async/forEach.js:80:24)
at ExceptionHandler._uncaughtException (/home/ubuntumachine/Desktop/project/node_modules/winston/lib/winston/exception-handler.js:203:5)
at process.emit (events.js:198:13)
(node:20805) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 31 error listeners added. Use emitter.setMaxListeners() to increase limit
at _addListener (events.js:256:17)
at Console.addListener (events.js:272:10)
at Console.once (events.js:301:8)
at asyncForEach (/home/ubuntumachine/Desktop/project/node_modules/winston/lib/winston/exception-handler.js:217:17)
at /home/ubuntumachine/Desktop/project/node_modules/async/internal/withoutIndex.js:9:16
at eachOfArrayLike (/home/ubuntumachine/Desktop/project/node_modules/async/eachOf.js:65:9)
at exports.default (/home/ubuntumachine/Desktop/project/node_modules/async/eachOf.js:9:5)
at eachLimit (/home/ubuntumachine/Desktop/project/node_modules/async/forEach.js:80:24)
at ExceptionHandler._uncaughtException (/home/ubuntumachine/Desktop/project/node_modules/winston/lib/winston/exception-handler.js:203:5)
at process.emit (events.js:198:13)
试图将最大侦听器设置为无穷大,
const EventEmitter = require('events');
const emitter = new EventEmitter();
emitter.setMaxListeners(Infinity);
仍然面临同样的问题。
答案 0 :(得分:2)
我遇到了一个相关案例,并在标题中提到了警告,因此,我只是将我的调查中的见解分享给可能会参与此话题的其他人:
process.setMaxListeners(0);
,与问题中使用的语言不同。答案 1 :(得分:0)
我遇到了同样的问题,在完成记录器后,通过调用winstonLoggerInstance.clear()
来解决此问题。 clear()
清除所有传输。
答案 2 :(得分:-1)
如下所示设置handleExceptions: false
createLogger({
level: 'info',
transports: [
new transports.Console({
format: format.combine(
format.colorize(),
format.simple(),
myFormat
),
handleExceptions: false
})
],
format: logFormat(label)
})