-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlog.js
50 lines (43 loc) · 1.45 KB
/
log.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
const winston = require("winston")
const winstonDaily = require("winston-daily-rotate-file")
const process = require("process")
const { combine, timestamp, label, printf } = winston.format
const logDir = process.env.LOG || `./logs`
const logFormat = printf(({ level, message, label, timestamp }) => {
return `${timestamp} [${label}] ${level}: ${message}` // 날짜 [시스템이름] 로그레벨 메세지
})
const logger = winston.createLogger({
format: combine(
timestamp({ format: "YYYY-MM-DD HH:mm:ss" }),
label({ label: "Carryduo Data-Analysis" }),
logFormat
),
transports: [
new winstonDaily({
level: "info",
datePattern: "YYYY-MM-DD",
dirname: logDir + "/info",
filename: `%DATE%.log`,
maxFiles: 7,
zippedArchive: true,
}),
new winstonDaily({
level: "error",
datePattern: "YYYY-MM-DD",
dirname: logDir + "/error",
filename: `%DATE%.error.log`,
maxFiles: 7,
zippedArchive: true,
}),
],
})
// prod 개발환경이 아닌 경우에는 로그 남기면서 콘솔까지 남김
if (process.env.NODE_ENV !== "production") {
logger.add(
new winston.transports.Console({
handleExceptions: true,
format: winston.format.combine(winston.format.colorize(), winston.format.simple()),
})
)
}
module.exports = logger