method One:
Direct reference to 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 don't postfix log file with process ID
--log-date-format <format> prefix logs with format Ed 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 a 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 are 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 would usually be written in the Pm2_home (~/.pm2/logs). Method Two:
Modify the Conf.js in the ~/.PM2 directory
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 '),//Case
such as modifying the default location of the PM2 logs. Default_log_path: '/data/pm2logs ', Dump_file_path:p.join (pm2_home, ' dump.pm2 '), daemon_rpc_p Ort:p.join (pm2_home, ' Rpc.sock '), Daemon_pub_port:p.join (Pm2_home, ' Pub.sock '), Interactor_r Pc_port:p.join (pm2_home, ' Interactor.sock '), Graceful_timeout:parseint (Process.env.PM2_GRACEFUL_TIME Out) | | 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
};
The
does not take effect immediately after the modifications are completed.
Execute the PM2 kill PM2 and then? Execute PM2 Start your configuration to make the changes take effect.