-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogger.js
46 lines (42 loc) · 1.22 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
const padLeft = (month) => month < 10 ? '0' + month : month;
const formatDate = () => {
const now = new Date;
const year = now.getFullYear();
const month = now.getMonth() + 1;
const day = now.getDate();
const hour = now.getHours();
const minutes = now.getMinutes();
const seconds = now.getSeconds();
return [
year,
padLeft(month),
padLeft(day),
].join('/') + ' ' + [
padLeft(hour),
padLeft(minutes),
padLeft(seconds),
].join(':')
};
const nginxFormat = info => formatDate() + ` [${info.level}] ${process.pid}: ${info.message}`;
const logger = winston.createLogger({
level: 'info',
format: winston.format.simple(),
defaultMeta: {service: 'user-service'},
transports: [
new winston.transports.File({
filename: path.join(LOG_DIR, 'error.log'),
level: 'error',
format: format.combine(
format.splat(),
format.printf(nginxFormat)
)
}),
new winston.transports.Console({
format: format.combine(
format.splat(),
format.printf(nginxFormat)
)
}),
]
});
module.exports = logger;