Unitech / pm2

Node.js Production Process Manager with a built-in Load Balancer.
https://pm2.keymetrics.io/docs/usage/quick-start/
Other
41.52k stars 2.63k forks source link

log_date_format does not add timestamps to the error log #4519

Open adamhl8 opened 4 years ago

adamhl8 commented 4 years ago

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 commented 4 years ago

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

adamhl8 commented 4 years ago

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?

Unitech commented 4 years ago

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

adamhl8 commented 4 years ago

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.

MumiaIrrequieta commented 4 years ago

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

adamhl8 commented 4 years ago

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

stale[bot] commented 4 years ago

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.

AlisaLiCn commented 3 years ago

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

dazjean commented 2 years ago

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

Vanav commented 1 month ago

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"}