简体   繁体   中英

Get node console output to file with pm2

How can I get node console output (such as errors) to a file with pm2? I tried to run pm2 task --log-type json but it didn't work

There is no log file in /var/log or in the project directory.

How can I achieve this?

Just add log property to your ecosystem config file like this:

module.exports = {
  apps: [
    {
      name: name,
      script: './server/server.js',
      error_file: './logs/err.log',
      out_file: './logs/out.log',
      log_date_format: 'YYYY-MM-DD HH:mm:ss:SSS',
    }
  ]
}

Then pm2 will automate write log into these file (one for console.log and one for console.error)

Use pm2 list and note process-id for which you want to see the log.

Save the executed process using pm2 save

Then, enter pm2 logs process-id to see the logs and report of respective pm2 process.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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