Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add dates to pm2 error logs?

Tags:

node.js

pm2

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

like image 219
Plastic Rabbit Avatar asked Jan 23 '14 19:01

Plastic Rabbit


People also ask

Does pm2 auto restart?

PM2 will keep your application forever alive, auto-restarting across crashes and machine restarts.

How do you reset pm2 service?

Restart on file change To totally disable the watch feature, do: pm2 stop app --watch or toggle the watch option on application restart via pm2 restart app --watch .


1 Answers

As per the pm2 logs official documentation, you can use --time, which prefixes logs with a standard formatted timestamp.

pm2 start app.js --time  

If you have already created the app, you can update it while restarting the application with:

pm2 restart 0 --time 

Make sure to pm2 save afterwards.

Note that you can also use a custom formatter as per this issue & this commit:

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.

like image 193
AbdelHady Avatar answered Oct 10 '22 05:10

AbdelHady