Warm tip: This article is reproduced from stackoverflow.com, please click
node.js pm2

How to add dates to pm2 error logs?

发布于 2020-03-27 10:28:15

Is there a way to add timestamps to error logs in .pm2/logs?

I noticed that pm2 logs command shows aggregated logs with timestamps, but looking into log files - there are only messages and stacktraces without dates.

enter image description here

Questioner
Plastic Rabbit
Viewed
158
AbdelHady 2020-03-06 01:58

As per this issue & this commit, you can use:

pm2 start app.js --log-date-format 'DD-MM HH:mm:ss.SSS'

where 'DD-MM HH:mm:ss.SSS' is any momentjs valid format.

-- Update --

As per the pm2 logs official documentation, now you can use the simpler --time, like:

pm2 start app.js --time

where --time prefixs logs with standard formatted timestamp.