From db0ff3ebf17188aa3788d3401e9ce8af8ff3d7f3 Mon Sep 17 00:00:00 2001 From: danghongquan Date: Sat, 30 Nov 2024 15:49:15 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E5=A2=9E=E5=8A=A0=E6=97=A5=E5=BF=97?= =?UTF-8?q?=E8=BD=AC=E5=82=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: danghongquan --- ai/ai.js | 2 +- package.json | 1 + winston.config.js | 34 +++++++++++++++++++++++++--------- 3 files changed, 27 insertions(+), 10 deletions(-) diff --git a/ai/ai.js b/ai/ai.js index 31ca1fb..13ae385 100644 --- a/ai/ai.js +++ b/ai/ai.js @@ -141,7 +141,7 @@ function hasKeys(obj) { // 判断两个值是否都不为空 return startTimeNotEmpty && endTimeNotEmpty; } - return false + return false; } // 将信息send至服务器 diff --git a/package.json b/package.json index f533aac..bad6983 100644 --- a/package.json +++ b/package.json @@ -18,6 +18,7 @@ "socket.io": "^4.7.5", "unzipper": "^0.12.3", "winston": "^3.17.0", + "winston-daily-rotate-file": "^5.0.0", "ws": "^8.18.0" } } diff --git a/winston.config.js b/winston.config.js index 2df7a13..e04c271 100644 --- a/winston.config.js +++ b/winston.config.js @@ -1,19 +1,35 @@ const winston = require('winston'); +const DailyRotateFile = require('winston-daily-rotate-file'); + +const transport = new DailyRotateFile({ + // 日志文件名称,%DATE%会被替换成当前日期 + filename: 'application-%DATE%.log', + // 日志文件的目录 + dirname: './logs', + // 日志文件的日期格式和轮转时间间隔 + datePattern: 'YYYY-MM-DD', + // 是否压缩旧的日志文件 + zippedArchive: true, + // 最大文件大小(单位:字节) + maxSize: '20m', + // 保留日志文件的最大天数 + maxFiles: '1d', + // 格式化日志 + format: winston.format.combine( + winston.format.timestamp({ + format: 'YYYY-MM-DD HH:mm:ss' + }), + winston.format.printf(info => `${info.timestamp} ${info.level}: ${info.message}`), + winston.format.errors({ stack: true }) + ) + }); module.exports = { // 定义日志级别 level: 'info', - // 定义日志格式 - format: winston.format.combine( - winston.format.timestamp({ - format: 'YYYY-MM-DD HH:mm:ss' - }), - winston.format.errors({ stack: true }), - winston.format.json() - ), // 定义日志传输方式 transports: [ // 记录到文件 - new winston.transports.File({ filename: 'combined.log' }) + transport ] }; \ No newline at end of file -- Gitee