方法一:


直接引用 pm2官方的:
http://pm2.keymetrics.io/docs/usage/log-management/

Log configuration


CLI

Example:

1
$ pm2 start echo.js --merge-logs --log-date-format="YYYY-MM-DD HH:mm Z"

Options:

1
2
3
4
5
--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

1
2
3
4
5
6
7
 {
"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:

1
2
3
4
5
{
"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:

1
2
3
4
{
"out_file": "combined.log",
"err_file": "combined.log"
}

Note that relatives logs paths will usually be written in the PM2_HOME (~/.pm2/logs) .

方法二:


修改 ~/.pm2 目录下的 conf.js

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
//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'),
//例如修改默认的 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;
};

修改完之后还不是立即生效.
执行一下 pm2 kill 来 杀掉 pm2 然后 执行 pm2 start 你的配置 来使修改生效.

感谢您的阅读,本文由 smallwhite's Blog 版权所有。如若转载,请注明出处:smallwhite's Blog(https://smallwhite.ml/pub/uncategorized/pm2-zi-ding-yi-log-pid-deng-ri-zhi-wen-jian-wei-zhi.html
nodejs javascript 实现随机数种子的几种方法
解决 ssh user@ip 'command' 出现 'command not found'的问题