Make pm2 log to console

家住魔仙堡 提交于 2019-12-03 14:57:05

问题


I am running a node webserver using pm2. Since pm2 spawns another process and redirects stdout and stderr to files, I have to look somewhere else for the logs. Ideally, I would like to have the node process output to the same console window that I've run pm2 from. Otherwise, I would settle for pm2 run the node process with an active console window and have stdout and stderr of the node process write to that console window. How can this be achieved? I'm on a windows machine.


回答1:


I believe you can also see the stdout and stderr of a process that is running daemonized by the command pm2 logs or pm2 logs [app-name].




回答2:


Found the answer (their documentation is not that great), just added the --no-daemon flag, seems to have done it. Although, it appears that it's still logging to the file (even when using the flag) on the first uptime. Once the process gets restarted (I'm watching for file changes) it starts logging out to the console




回答3:


programmatically you can do something like this:

const pm2 = require('pm2')

pm2.connect(function(err) {
  if (err) {
    console.error(err);
    process.exit(2);
  }
  pm2.start([
    {
      script             : "server.js",
      output: "/dev/stdout",
      error: "/dev/stderr",
    },
  ]
    , function(err, proc) {
      if(err) {
        throw err
      }
    });
})


来源:https://stackoverflow.com/questions/36075460/make-pm2-log-to-console

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!