pm2 在 cluster 模式下启动,导致 log4js 不正常输出日志


pm2 在 cluster 模式下启动,导致 log4js 不正常输出日志

需要添加 disableClustering: true

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
'use strict';

let log4js = require('log4js');

log4js.configure({
disableClustering: true,// pm2在cluster模式下启动,导致log4js不正常输出日志
appenders: {
console: {type: 'console'},
errorFile: {
type: 'dateFile',
filename: 'logs/error',
pattern: 'yyyy-MM-dd.log',
maxLogSize: 10 * 1000 * 1000,
numBackups: 3,
alwaysIncludePattern: true
}
},
categories: {
default: {appenders: ['console'], level: 'info'},
error: {appenders: ['console', 'errorFile'], level: 'error'}
}
});

let errorLogger = log4js.getLogger('error');

function error(msg) {
errorLogger.error(msg);
}
exports.error = error;