diff --git a/log/index.ts b/log/index.ts index 4fd6aad..2cb6921 100644 --- a/log/index.ts +++ b/log/index.ts @@ -4,24 +4,6 @@ import winston, { format } from "winston" const isProd = process.env.NODE_ENV === "production" -const dailyRotateFileTransport4Info = new winston.transports.DailyRotateFile({ - level: "info", - filename: "/home/work/log/egg-info-%DATE%.log", - datePattern: "YYYY-MM-DD", - zippedArchive: true, - maxSize: "20m", - maxFiles: "14d", -}) - -const dailyRotateFileTransport4Debug = new winston.transports.DailyRotateFile({ - level: "debug", - filename: "/home/work/log/egg-debug-%DATE%.log", - datePattern: "YYYY-MM-DD", - zippedArchive: true, - maxSize: "20m", - maxFiles: "14d", -}) - const transports: any[] = [ new winston.transports.Console({ level: "info", @@ -29,8 +11,27 @@ const transports: any[] = [ ] if (isProd) { - transports.push(dailyRotateFileTransport4Info) - transports.push(dailyRotateFileTransport4Debug) + const config = { + datePattern: "YYYY-MM-DD", + zippedArchive: true, + maxSize: "20m", + maxFiles: "14d", + } + + transports.push( + new winston.transports.DailyRotateFile({ + level: "info", + filename: "/home/work/log/egg-info-%DATE%.log", + ...config, + }) + ) + transports.push( + new winston.transports.DailyRotateFile({ + level: "debug", + filename: "/home/work/log/egg-debug-%DATE%.log", + ...config, + }) + ) } const loggerIns = winston.createLogger({ diff --git a/package.json b/package.json index 5b1db5f..9b7a8bc 100644 --- a/package.json +++ b/package.json @@ -4,6 +4,7 @@ "type": "module", "scripts": { "start": "bun run index.ts", + "dev": "NODE_ENV=dev bun run index.ts --watch", "lint": "eslint --fix .", "prepare": "husky", "prettier": "prettier --write ."