pm2 ignores log_date_format
What's going wrong?
I set in ecosystem: log_date_format: 'YYYY-MM-DD HH:mm Z' also I tried other formats, pm2 ignores all
But in env: log_date_format: YYYY-MM-DDTHH:mm:ss
And in logs: 18|pm2-debug | 2022-10-16T09:46:08: 2022-10-16T09:46:08.689Z 18|pm2-debug | 2022-10-16T09:46:09: 2022-10-16T09:46:09.689Z
How could we reproduce this issue?
pm2 start pm2.config.yml
pm2 env <id> | grep log
log_date_format: YYYY-MM-DDTHH:mm:ss
Also i tried run from console, same result
pm2 start index.js --name pm2-debug --time --log-date-format "YYYY-MM-DD HH:mm Z"
index.js
var myInt = setInterval(function () {
console.log(new Date().toISOString());
}, 1000);
pm2.config.yml
apps:
- name: 'pm2-debug'
script: 'index.js'
cwd: '/var/web/pm2-debug'
instances: '1'
exec_mode: 'cluster'
time: true
log_date_format: 'YYYY-MM-DD HH:mm Z'
error_file: './error.log'
out_file: './access.log'
env:
NODE_ENV: 'production'
HOST: '127.0.0.1'
PORT: '30100'
umask: '0002'
Supporting information
pm2 report
--- PM2 report ----------------------------------------------------------------
Date : Sun Oct 16 2022 09:27:52 GMT+0000 (Всемирное координированное время)
===============================================================================
--- Daemon -------------------------------------------------
pm2d version : 5.2.2
node version : 16.17.1
node path : not found
argv : /usr/bin/node,/usr/lib/node_modules/pm2/lib/Daemon.js
argv0 : node
user : root
uid : 0
gid : 0
uptime : 39min
===============================================================================
--- CLI ----------------------------------------------------
local pm2 : 5.2.2
node version : 16.17.1
node path : /usr/bin/pm2
argv : /usr/bin/node,/usr/bin/pm2,report
argv0 : node
user : root
uid : 0
gid : 0
===============================================================================
--- System info --------------------------------------------
arch : x64
platform : linux
type : Linux
cpus : Intel(R) Xeon(R) E-2386G CPU @ 3.50GHz
cpus nb : 6
freemem : 5208940544
totalmem : 8342847488
home : /root
===============================================================================
--- PM2 list -----------------------------------------------
┌─────┬────────────────────────────────────────────────┬─────────────┬─────────┬─────────┬──────────┬────────┬──────┬───────────┬──────────┬──────────┬──────────┬──────────┐
│ id │ name │ namespace │ version │ mode │ pid │ uptime │ ↺ │ status │ cpu │ mem │ user │ watching │
├─────┼────────────────────────────────────────────────┼─────────────┼─────────┼─────────┼──────────┼────────┼──────┼───────────┼──────────┼──────────┼──────────┼──────────┤
└─────┴────────────────────────────────────────────────┴─────────────┴─────────┴─────────┴──────────┴────────┴──────┴───────────┴──────────┴──────────┴──────────┴──────────┘
Module
┌────┬──────────────────────────────┬───────────────┬──────────┬──────────┬──────┬──────────┬──────────┬──────────┐
│ id │ module │ version │ pid │ status │ ↺ │ cpu │ mem │ user │
├────┼──────────────────────────────┼───────────────┼──────────┼──────────┼──────┼──────────┼──────────┼──────────┤
│ 0 │ pm2-logrotate │ 2.7.0 │ 1175075 │ online │ 0 │ 0.1% │ 57.4mb │ root │
└────┴──────────────────────────────┴───────────────┴──────────┴──────────┴──────┴──────────┴──────────┴──────────┘
===============================================================================
--- Daemon logs --------------------------------------------
/root/.pm2/pm2.log last 20 lines:
PM2 | 2022-10-16T08:48:24: PM2 log: App [pm2-debug:15] starting in -cluster mode-
PM2 | 2022-10-16T08:48:24: PM2 log: App [pm2-debug:15] online
PM2 | 2022-10-16T08:55:02: PM2 log: Stopping app:pm2-debug id:15
PM2 | 2022-10-16T08:55:02: PM2 log: App name:pm2-debug id:15 disconnected
PM2 | 2022-10-16T08:55:02: PM2 log: App [pm2-debug:15] exited with code [0] via signal [SIGINT]
PM2 | 2022-10-16T08:55:02: PM2 log: pid=1175275 msg=process killed
PM2 | 2022-10-16T09:22:48: PM2 log: App [index:16] starting in -fork mode-
PM2 | 2022-10-16T09:22:48: PM2 log: App [index:16] online
PM2 | 2022-10-16T09:24:03: PM2 log: Stopping app:index id:16
PM2 | 2022-10-16T09:24:03: PM2 log: App [index:16] exited with code [0] via signal [SIGINT]
PM2 | 2022-10-16T09:24:03: PM2 log: pid=1175465 msg=process killed
PM2 | 2022-10-16T09:24:17: PM2 log: App [pm2-debug:17] starting in -fork mode-
PM2 | 2022-10-16T09:24:17: PM2 log: App [pm2-debug:17] online
PM2 | 2022-10-16T09:25:34: PM2 log: Stopping app:pm2-debug id:17
PM2 | 2022-10-16T09:25:34: PM2 log: App [pm2-debug:17] exited with code [0] via signal [SIGINT]
PM2 | 2022-10-16T09:25:34: PM2 log: pid=1175536 msg=process killed
Works if you remove the --time argument and just leave the --log-date-format
Hi,
I'm not entirely sure I fully understand the code, but there seems to be a bug on Common.js#L745's verifyConfs() method, where it should be picking up the configuration value of log_date_format, instead it always assigns it back to the default value of YYYY-MM-DDTHH:mm:ss:
/**
* Add log_date_format by default
*/
if (app.time || process.env.ASZ_MODE) {
app.log_date_format = 'YYYY-MM-DDTHH:mm:ss'
}
When I change that line to:
/**
* Add log_date_format by default
*/
if (app.time || process.env.ASZ_MODE) {
app.log_date_format = app.log_date_format ?? 'YYYY-MM-DDTHH:mm:ss'
}
then using the log_date_format variable works as expected both when issuing a command like:
pm2 start script.js –log-date-format 'YYYY-MM-DDTHH:mm:ss.SSS'
or when log_date_format is set in an ecosystem.js file:
//... other configurations
log_date_format: "YYYY-MM-DDTHH:mm:ss.SSS",
//.. rest of ecosystem file
Without this change, the value of log_date_format is ignored when set in ecosystem files of any kind (and whether exec_mode is set to cluster or not).
I might be missing something, but this seems like a simple fix?