-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogger.js
44 lines (41 loc) · 1.5 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
const winston = require("winston");
const DailyRotateFile = require("winston-daily-rotate-file");
const myFormat = winston.format.printf(({ timestamp, level, message }) => {
const date = new Date(timestamp);
const formattedDate = `${date.getDate().toString().padStart(2, "0")}.${(
date.getMonth() + 1
)
.toString()
.padStart(2, "0")}.${date.getFullYear()}`;
const formattedTime = `${date.getHours().toString().padStart(2, "0")}:${date
.getMinutes()
.toString()
.padStart(2, "0")}:${date.getSeconds().toString().padStart(2, "0")}`;
return `${formattedDate} | ${formattedTime} | ${level} | ${message}`;
});
const logger = winston.createLogger({
level: "debug", // Log only if info.level <= this level
format: winston.format.combine(
winston.format.timestamp(),
winston.format.json(),
),
transports: [
// Write all logs with level `info` and below to a daily rotate file
new DailyRotateFile({
filename: "logs/%DATE%.log",
datePattern: "YYYY-MM-DD",
zippedArchive: true,
maxSize: "20m",
maxFiles: "14d",
format: winston.format.combine(winston.format.timestamp(), myFormat),
}),
new winston.transports.Console({
format: winston.format.combine(
winston.format.timestamp(),
winston.format.colorize(),
myFormat
),
}),
],
});
module.exports = logger;