2022-09-21 05:05:03 +00:00
|
|
|
import winston from "winston";
|
|
|
|
import "winston-daily-rotate-file";
|
|
|
|
|
|
|
|
export const logger = winston.createLogger({
|
|
|
|
levels: {
|
|
|
|
error: 0,
|
|
|
|
warn: 1,
|
|
|
|
info: 2,
|
|
|
|
main: 3,
|
|
|
|
debug: 4
|
|
|
|
},
|
|
|
|
transports: [
|
|
|
|
new winston.transports.Console({ format: winston.format.colorize({ all: true }), stderrLevels: ["error", "warn"] }),
|
|
|
|
new winston.transports.DailyRotateFile({ filename: "logs/error-%DATE%.log", level: "error", zippedArchive: true, maxSize: 4194304, maxFiles: 8 }),
|
|
|
|
new winston.transports.DailyRotateFile({ filename: "logs/main-%DATE%.log", zippedArchive: true, maxSize: 4194304, maxFiles: 8 })
|
|
|
|
],
|
|
|
|
level: process.env.DEBUG_LOG ? "debug" : "main",
|
|
|
|
format: winston.format.combine(
|
|
|
|
winston.format.timestamp({ format: "YYYY-MM-DD HH:mm:ss" }),
|
|
|
|
winston.format.printf((info) => {
|
|
|
|
const {
|
|
|
|
timestamp, level, message, ...args
|
|
|
|
} = info;
|
|
|
|
|
|
|
|
return `[${timestamp}]: [${level.toUpperCase()}] - ${message} ${Object.keys(args).length ? JSON.stringify(args, null, 2) : ""}`;
|
|
|
|
}),
|
|
|
|
)
|
|
|
|
});
|
|
|
|
|
|
|
|
winston.addColors({
|
|
|
|
info: "green",
|
|
|
|
main: "gray",
|
|
|
|
debug: "magenta",
|
|
|
|
warn: "yellow",
|
|
|
|
error: "red"
|
|
|
|
});
|
|
|
|
|
|
|
|
export function log(type, content) { return content ? logger.log(type === "log" ? "main" : type, content) : logger.info(type); }
|
2019-09-13 20:02:41 +00:00
|
|
|
|
2021-08-19 14:19:14 +00:00
|
|
|
export function error(...args) { return log("error", ...args); }
|
2019-09-13 20:02:41 +00:00
|
|
|
|
2021-08-19 14:19:14 +00:00
|
|
|
export function warn(...args) { return log("warn", ...args); }
|
2019-09-13 20:02:41 +00:00
|
|
|
|
2021-08-19 14:19:14 +00:00
|
|
|
export function debug(...args) { return log("debug", ...args); }
|