Reputation: 1357
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?
Upvotes: 1
Views: 6111
Reputation: 1330
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.
Upvotes: 3
Reputation: 1156
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)
Upvotes: 1