问题描述
如果我在fork模式下为node js应用程序运行pm2进程,则会生成日志,但如果在pm2集群模式下运行,则同一应用程序不会提供日志
我正在使用下面的pm2生态系统文件启动我的应用
module.exports = {
apps : [
{
name: 'test',script: <entry_file_path>,exec_mode: "cluster",instances: 1,autorestart: true,watch: false,combine_logs:true,max_memory_restart: '1G',exp_backoff_restart_delay: 1000,merge_logs: true,env: {
NODE_ENV: 'production'
}
}]
};
我正在使用log4js v5.2.2登录我的节点应用
解决方法
根据@MAS的建议,以下配置对我有用
运行此命令“ pm2 install pm2-intercom” &然后在log4js配置中添加pm2:true
log4js.configure({
appenders: { out: { type: 'stdout'}},categories: { default: { appenders: ['out'],level: 'info'}},pm2: true
});
有关更多详细信息,请参见https://github.com/log4js-node/log4js-node/blob/master/docs/clustering.md