简体   繁体   English

pm2集群模式不输出日志

[英]pm2 cluster mode not outputting logs

node: 12.13.0节点:12.13.0

pm2: 4.2.3下午2:4.2.3

The issue is where nothing is printed in pm2-out and pm2-err log files instead of a few lines that pm2 prints the script which is executing.问题是在 pm2-out 和 pm2-err 日志文件中没有打印任何内容,而不是 pm2 打印正在执行的脚本的几行。 I tried both with Winston and Debug loggers.我尝试了 Winston 和 Debug 记录器。 When I start in fork mode all logs are printed.当我以 fork 模式启动时,所有日志都会打印出来。 Also, pm2 logs show the logs but files are empty.此外, pm2 logs显示日志但文件为空。

I use merge_logs to avoid splitting out or err logs into multiple files per process.我使用merge_logs来避免将每个进程的日志拆分或错误记录到多个文件中。

I also tried with specifying log names but without luck.我也尝试过指定日志名称,但没有运气。 If anyone can help me, thank you in advance.如果有人可以帮助我,请提前致谢。

PS I don't want to use Winston output to file. PS 我不想使用 Winston 输出到文件。 Also, with pm2 monit I don't see anything.另外,使用pm2 monit我什么也没看到。

ecosystem.config.js :生态系统.config.js :

module.exports = {
 apps: [
    {
        name: 'client',
        script: 'npm',
        args: 'run start:client',
        cwd: '/mnt/data/app',
        watch: false,
        log_date_format: 'DD-MM-YYYY HH:mm',
        exec_mode: 'cluster',
        instances: '2',
        merge_logs: true,
        env: {
            PORT: 8080,
            NODE_ENV: 'production',
        },
    },
    {
        name: 'server',
        script: 'npm',
        args: 'run start:server',
        cwd: '/mnt/data/app',
        watch: false,
        log_date_format: 'DD-MM-YYYY HH:mm',
        exec_mode: 'cluster',
        instances: '2',
        merge_logs: true,
        env: {
            PORT: 3000,
            NODE_ENV: 'production',
           },
       },
    ],
};

run this command pm2 install pm2-intercom might work without this &运行这个命令pm2 install pm2-intercom可能没有这个&

then add pm2: true in log4js config like the following :然后在log4js配置中添加pm2 pm2: true ,如下所示:

log4js.configure({
    appenders: { 
        out: { 
            type: 'stdout'
        }
    },
    categories: { 
        default: { 
            appenders: ['out'], 
            level: 'info'
        }
    },
    pm2: true
});

for more details, refer https://github.com/log4js-node/log4js-node/blob/master/docs/clustering.md有关更多详细信息,请参阅https://github.com/log4js-node/log4js-node/blob/master/docs/clustering.md

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM