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?
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-
pm2 restart 0 --log-date-format "HH:MM DD-MM-YYYY Z"
pm2 save
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
Most helpful comment
I fixed it by doing following-