-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathlogger.js
76 lines (72 loc) · 1.52 KB
/
logger.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
const log4js = require('log4js');
const developmentAppenders = {
console: {
type: 'console',
},
dev: {
type: 'file',
filename: './logs/debug.log',
layout: {
type: 'pattern',
pattern: '[%d{yyyy-MM-dd hh:mm:ss}] [%-5p] [%c] - %m',
},
maxLogSize: 5242880, // 5MB
backups: 3,
},
};
const productionAppenders = {
app: {
type: 'file',
filename: './logs/app.log',
layout: {
type: 'pattern',
pattern: '[%d{yyyy-MM-dd hh:mm:ss}] [%-5p] [%c]- %m',
},
maxLogSize: 10485760,
backups: 10,
keepFileExt: true,
compress: true,
},
emergencies: {
type: 'file',
filename: './logs/error.log',
layout: {
type: 'pattern',
pattern: '[%d{yyyy-MM-dd hh:mm:ss}] [%-5p] [%c]- %m',
},
maxLogSize: 10485760, // 10MB
backups: 5,
keepFileExt: true,
compress: true,
},
'just-errors': {
type: 'logLevelFilter',
appender: 'emergencies',
level: 'error',
},
};
const logger = LABEL => {
if (['development', 'debug'].includes(process.env.NODE_ENV)) {
log4js.configure({
appenders: developmentAppenders,
categories: {
default: {
appenders: ['dev', 'console'],
level: 'debug',
},
},
});
return log4js.getLogger(LABEL);
}
log4js.configure({
appenders: productionAppenders,
categories: {
default: {
appenders: ['just-errors', 'app'],
level: 'info',
},
},
});
return log4js.getLogger(LABEL);
};
module.exports = logger;