Method one:
Direct reference pm2 official:
http://pm2.keymetrics.io/docs/usage/log-management/
Log configuration
CLI
Example:
$ pm2 start echo.js --merge-logs --log-date-format="YYYY-MM-DD HH:mm Z"
Options:
--merge-logs do not postfix log file with process id
--log-date-format <format> prefix logs with formated timestamp
-l --log [path] specify entire log file (error and out are both included)
-o --output <path> specify out log file
-e --error <path> specify error log file
JSON way
{
"script" : "echo.js",
"error_file" : "err.log",
"out_file" : "out.log",
"merge_logs" : true,
"log_date_format" : "YYYY-MM-DD HH:mm Z"
}
Combine out and err logs
To combine all logs into the same file set the same value for error_file, out_file or use an additional log_file.
For example, this keeps out and err separated but adds a combined file:
{
"log_file": "combined.outerr.log",
"out_file": "out.log",
"err_file": "err.log"
}
Or if you want out and err combined without any other file, just use the same log file:
{
"out_file": "combined.log",
"err_file": "combined.log"
}
Note that relatives logs paths will usually be written in the PM2_HOME (~/.pm2/logs)
.
Method 2:
Modify ~/. Pm2
directory conf.js
//conf.js
/**
* Overidde PM2 configuration
*/
var p = require('path');
module.exports = function(DEFAULT_HOME) {
if (!DEFAULT_HOME)
return false;
var PM2_HOME = DEFAULT_HOME;
var pm2_conf = {
PM2_HOME : PM2_HOME,
PM2_LOG_FILE_PATH : p.join(PM2_HOME, 'pm2.log'),
PM2_PID_FILE_PATH : p.join(PM2_HOME, 'pm2.pid'),
DEFAULT_PID_PATH : p.join(PM2_HOME, 'pids'),
//For example, changing the default location of pm2 logs.
DEFAULT_LOG_PATH : '/data/pm2logs',
DUMP_FILE_PATH : p.join(PM2_HOME, 'dump.pm2'),
DAEMON_RPC_PORT : p.join(PM2_HOME, 'rpc.sock'),
DAEMON_PUB_PORT : p.join(PM2_HOME, 'pub.sock'),
INTERACTOR_RPC_PORT : p.join(PM2_HOME, 'interactor.sock'),
GRACEFUL_TIMEOUT : parseInt(process.env.PM2_GRACEFUL_TIMEOUT) || 8000,
GRACEFUL_LISTEN_TIMEOUT : parseInt(process.env.PM2_GRACEFUL_LISTEN_TIMEOUT) || 3000,
CONCURRENT_ACTIONS : parseInt(process.env.PM2_CONCURRENT_ACTIONS) || 1,
DEBUG : process.env.PM2_DEBUG || false,
WEB_INTERFACE : parseInt(process.env.PM2_API_PORT) || 9615,
MODIFY_REQUIRE : process.env.PM2_MODIFY_REQUIRE || false,
PM2_LOG_DATE_FORMAT : process.env.PM2_LOG_DATE_FORMAT !== undefined ?process.env.PM2_LOG_DATE_FORMAT : 'YYYY-MM-DD HH:mm:ss',
INTERACTOR_LOG_FILE_PATH : p.join(PM2_HOME, 'agent.log'),
INTERACTOR_PID_PATH : p.join(PM2_HOME, 'agent.pid'),
INTERACTION_CONF : p.join(PM2_HOME, 'agent.json5')
};
return pm2_conf || null;
};
execute pm2 kill
to kill the pm2 and then execute pm2 start your configuration
to make the change take effect.
Read More:
- Ubuntu: pdserving deployment output log.txt Error
- Nginx error: nginx: [error] invalid PID number ““ in “/run/nginx.pid“
- Linux Nagios failed to log in to internal server error (Fixed)
- [Solved] KingbaseES V8R3 Error: cluster.log ERROR: md5 authentication failed
- [Solved] nova-compute.log Error: Instance failed block device setup
- [Solved] Log Error: kernel: blk_update_request: I/O error, dev fd0, sector 0
- [Solved] Nginx Restart Error: /run/nginx.pid failed (2: No such file or directory)
- [Solved] mosquitto log Error: SSL routines:SSL3_READ_BYTES:tlsv1 alert decrypt error
- [Solved] nginx: [error] open() “/usr/local/nginx/nginx.pid” failed (2: No such file or directory)
- [Solved] Centos Mount Error: XFS: log mount mount/recovery failed : error -117
- Docker Startup Error: standard_init_linux.go:211: exec user process caused “no such file or directory”
- Linux gets the program PID according to the port
- Nginx Startup Error: “/var/run/nginx/nginx.pid” failed” [How to Solve]
- [Solved] Linux Perl Error: cannot locate cpan.pm in @inc (@inc contains:inc/usr/local/lib64/perl5/usr)
- Ionic Save to Gallery Plugin IOS Error: Method ‘requestAuthorization:’ not defined in Plugin ‘PhotoLibrary’ ERROR: Method ‘xxx’ not defined
- System has not been booted with systemd as init system (PID 1). Can‘t operate
- [Solved] ××: error while loading shared libraries: ××.so.19: cannot open shared object file: No such file or directory
- [Solved] docker Error: System has not been booted with systemd as init system (PID 1). Can‘t operate. Failed to con
- U-boot NFS download file error: loading: * * * error: File lookup fail solution
- [Solved] NameError: name ‘reload’ is not defined on ROS melody terminal