-
Notifications
You must be signed in to change notification settings - Fork 0
/
logger.js
34 lines (30 loc) · 861 Bytes
/
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
import winston from "winston";
import "winston-daily-rotate-file";
const logFormats = [
winston.format.timestamp({ format: "YYYY-MM-DD HH:mm:ss.SSS" }),
winston.format.printf((info) => (
`[${info.timestamp}][${info.level}] ${info.message}`
))
];
const fileRotateTransport = new winston.transports.DailyRotateFile({
filename: "bot-%DATE%.log",
dirname: "logs",
datePattern: "YYYY-MM-DD",
maxFiles: "21d",
level: "debug",
format: winston.format.combine(...logFormats)
});
const logger = winston.createLogger({
levels: winston.config.npm.levels,
transports: [
new winston.transports.Console({
format: winston.format.combine(
winston.format.colorize(),
...logFormats
),
level: process.env.NODE_ENV === "production" ? "warn" : "debug"
}),
fileRotateTransport
]
});
export default logger;