-
Notifications
You must be signed in to change notification settings - Fork 0
/
logger.js
48 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
47
48
const winston = require("winston");
const winstonDaily = require("winston-daily-rotate-file");
const appRoot = require("app-root-path");
const { createLogger } = require("winston");
const process = require("process");
const logDir = `${appRoot}/logs`;
const { combine, timestamp, label, printf } = winston.format;
const logFormat = printf(({ level, message, label, timestamp, ip, path }) => {
return `${timestamp} [${label}] ${level}: ${message} - IP: ${ip}, Path: ${path}`;
});
const logger = createLogger({
format: combine(label({ label: "HARP" }), timestamp(), logFormat),
transports: [
new winstonDaily({
level: "info",
datePattern: "YYYY-MM-DD",
dirname: `${logDir}/info`,
filename: "%DATE%.log",
maxSize: "20m",
maxFiles: "30d",
}),
new winstonDaily({
level: "error",
datePattern: "YYYY-MM-DD",
dirname: `${logDir}/error`,
filename: "%DATE%.error.log",
maxSize: "20m",
maxFiles: "30d",
}),
],
});
if (process.env.NODE_ENV != "prod") {
logger.add(
new winston.transports.Console({
format: winston.format.combine(
winston.format.colorize(),
winston.format.simple()
),
})
);
}
module.exports = logger;