pm2 icon indicating copy to clipboard operation
pm2 copied to clipboard

log_date_format does not add timestamps to the error log

Open adamhl8 opened this issue 5 years ago • 10 comments
trafficstars

I have my ecosystem.config.js file set up like this:

module.exports = {
  apps : [{
    name: 'app',
    script: 'app.js',
    instances: 1,
    autorestart: true,
    watch: false,
    log_date_format: "YYYY-MM-DD HH:mm:ss",
    error_file: "logs/errors.log",
    out_file: "logs/app.log"
  }]
};

I have timestamps in my out_file log, but none in my error_file log.

I'm using verison 4.1.2.

adamhl8 avatar Nov 23 '19 14:11 adamhl8

Turns out things like unhandled promise rejections won't be timestamped, but as long as you actually catch errors the timestamp works properly.

adamhl8 avatar Nov 24 '19 02:11 adamhl8

I closed this too quickly. Should have done more testing, sorry.

It looks like only caught errors are timestamped, any other error isn't. Is that intended?

adamhl8 avatar Nov 24 '19 02:11 adamhl8

Can you send me a sample code so I try it out

Unitech avatar Nov 25 '19 11:11 Unitech

For example:

var promise = new Promise(function(resolve, reject) {
  if (false) {
  }
  else {
    reject(Error("It broke"));
  }
});

promise.then().catch(console.error);

In my error log I'll get an entry with the correct timestamp: 2019-11-25 06:25:13: Error: It broke

If I remove the .catch, an error is logged with no timestamp: You have triggered an unhandledRejection, you may have forgotten to catch a Promise rejection: Error: It broke

This doesn't just apply to unhandled promise rejections though. If you have something like let foo = bar where bar doesn't exist it will throw an error without a timestamp. In other words, the only time I've seen errors have a timestamp is when I catch rejected promises.

adamhl8 avatar Nov 25 '19 11:11 adamhl8

I'm having the same issue with "exec_mode: cluster" on ecosystem.config.js. If I disable cluster mode it works.

PM2 version 4.1.2

MumiaIrrequieta avatar Nov 27 '19 12:11 MumiaIrrequieta

Yep, after setting exec_mode to "fork" the logging/timestamps work as expected. Thanks.

adamhl8 avatar Nov 27 '19 14:11 adamhl8

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar May 23 '20 22:05 stale[bot]

I'm having the same issue, when I use "exec_mode: cluster", my error_log files won't include timestamps, but when I change to fork mode, timestamps appear.

My PM2 version is v4.5.6

AlisaLiCn avatar May 08 '21 09:05 AlisaLiCn

I haveing the same issue, when i setting exec_mode as cluster. my PM2 version is v5.1.2

dazjean avatar Sep 29 '22 04:09 dazjean

I confirm this issue. Sometimes there is timestamp in error log, but most of time there is no timestamp for repeated errors during multiple days. ecosystem.config.cjs:

module.exports = {
  apps: [{
    name: 'games-admin',
    exec_mode: 'cluster',
    instances: '1',
    cwd: '/srv/games-admin/api',
    script: 'dist/main.js',
    args: '--name games-admin --time',
    interpreter_args: '',
    merge_logs: true,
    log_date_format: 'YYYY-MM-DD HH:mm:ss Z'
  }]
}

~/.pm2/logs/games-admin-error.log:

You have triggered an unhandledRejection, you may have forgotten to catch a Promise rejection:
PrismaClientValidationError: 
Invalid `this.db.tgChatMessage.create()` invocation in ...
...
You have triggered an unhandledRejection, you may have forgotten to catch a Promise rejection:
PrismaClientValidationError: 
Invalid `this.db.tgChatMessage.create()` invocation in ...
...
You have triggered an unhandledRejection, you may have forgotten to catch a Promise rejection:
PrismaClientValidationError: 
Invalid `this.db.tgChatMessage.create()` invocation in ...
...
2024-09-27 20:15:33 +03:00: error: [polling_error] {"code":"EFATAL","message":"EFATAL: Error: read ETIMEDOUT"}

Vanav avatar Sep 27 '24 19:09 Vanav