因为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