Pm2: Get PM2 log timestamps to match server time zone?

Created on 24 Jul 2018  路  16Comments  路  Source: Unitech/pm2

I am starting my app with the following command:
pm2 start index.js --name server --log-date-format="MM-DD hh:mm:ss.SSS A"

It works great but the timestamps do not match the time zone of my server. Instead it appears they are GMT. Is there a way to fix this?

Most helpful comment

I fixed it by doing following-

  • first update the format (make sure server timezone is what you want)
pm2 restart 0 --log-date-format "HH:MM DD-MM-YYYY Z" 
  • save all processes
pm2 save
  • run these
npm i -G pm2 //if not latest  
pm2 update

All 16 comments

Hello, please refer to the moment lib: https://momentjs.com/docs/#/parsing/string-format/

@Unitech
Unless I'm missing something this does not cover how to get PM2 to log using the server's set time zone. I have the server timezone set to US Los Angeles, but my logs in PM2 are still GMT. I assume there is a setting somewhere in PM2 that will allow my logs to display in the desired time zone?

I have also tried the following config file but my logs still do not appear in local time:
module.exports = { apps : [ // SERVER { name : 'server', script : 'index.js', log_date_format: 'MM-DD hh:mm:ss.SSS A', autorestart: true, env: { TZ: 'America/Los_Angeles' }, }, ], };

Also, to clarify. The last log statement occurred at 11:26 AM in Los Angeles, but my PM2 console log shows the time as 7 hours ahead:

0|server | 07-24 06:26:32.514 PM: Server live

If restart the server after changing server timezone, your server timezone would be used in log time.

@hkchakladar unless I'm missing something, this does not fix the issue. When I run date in terminal, I get the correct timestamp. However pm2 is still returning UTC time stamp.

I gave another quick look on this and I believe we'd need to have pm2 modified to use moment.utcOffset() (http://momentjs.com/docs/#/manipulating/utc-offset/) and allow users to set a config option for the offset.

@Unitech any chance this could be supported?

@yourfavorite did you restarted your server?

Yes. It does not fix the problem. For now I've just disabled timestamp logging for PM2 and I add the timestamps myself via a custom log function.

I am facing this issue too

same issue here.

Yes, this is actually a problem. PM2 is always on UTC, despite the timezone set in the OS.
Shouldn't be too hard to fix.

Same Issue #3391

I fixed it by doing following-

  • first update the format (make sure server timezone is what you want)
pm2 restart 0 --log-date-format "HH:MM DD-MM-YYYY Z" 
  • save all processes
pm2 save
  • run these
npm i -G pm2 //if not latest  
pm2 update

@shahidcodes for the date format make sure to use HH:mm instead of HH:MM because m is for minute and M is for Month, otherwise it will display the month where the minutes should be shown

pm2 restart 0 --log-date-format "HH:MM DD-MM-YYYY Z"

HH:mm, not HH:MM because MM means month

Was this page helpful?
0 / 5 - 0 ratings