因为pm2涉及到了多线程,所以log4js在写入日志文件的时候如果并发写入就会丢掉部分信息。这里收集了一些解决办法:
If you’re running log4js in an application that uses node’s core cluster then log4js will transparently handle making sure the processes don’t try to log at the same time. All logging is done on the master process, with the worker processes sending their log messages to the master via process.send. This ensures that you don’t get multiple processes trying to write to the same file (or rotate the log files) at the same time.
This can cause problems in some rare circumstances, if you’re experiencing weird logging problems, then use the disableClustering: true option in your log4js configuration to have every process behave as if it were the master process. Be careful if you’re logging to files.
https://log4js-node.github.io/log4js-node/clustering.html
https://segmentfault.com/a/1190000018439311#articleHeader5
https://juejin.im/entry/5a0cf3276fb9a0450167814f
在使用PM2和Log4js进行日志记录时,由于多线程并发写入可能导致日志丢失。本文介绍了如何通过Log4js集群功能确保日志正确写入,避免多个进程同时操作同一文件的问题。
1497

被折叠的 条评论
为什么被折叠?



