From df304a358bffa66b0b986e740e0860bb86486ae7 Mon Sep 17 00:00:00 2001 From: TsMask <340112800@qq.com> Date: Mon, 30 Oct 2023 11:20:27 +0800 Subject: [PATCH 1/2] =?UTF-8?q?fix:=20=E8=B0=83=E6=95=B4=E6=97=A5=E5=BF=97?= =?UTF-8?q?=E8=BE=93=E5=87=BA=E6=96=87=E4=BB=B6restagent.log?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/framework/config/config/config.default.yaml | 4 ++-- src/framework/logger/writer.go | 14 +++++++------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/framework/config/config/config.default.yaml b/src/framework/config/config/config.default.yaml index 2a5daa64..674c85ad 100644 --- a/src/framework/config/config/config.default.yaml +++ b/src/framework/config/config/config.default.yaml @@ -13,9 +13,9 @@ server: # 日志 logger: fileDir: "/usr/local/omc/log" - fileName: "ems_agt.log" + fileName: "restagent.log" level: 2 # 日志记录的等级 0:silent<1:info<2:warn<3:error - maxDay: 30 # 日志会保留 30 天 + maxDay: 180 # 日志会保留 180 天 maxSize: 10 # 调整按 10MB 大小的切割 # 静态文件配置, 相对项目根路径或填绝对路径 diff --git a/src/framework/logger/writer.go b/src/framework/logger/writer.go index 70fca2c5..1a7a7058 100644 --- a/src/framework/logger/writer.go +++ b/src/framework/logger/writer.go @@ -84,13 +84,13 @@ func (l *Logger) checkFile() { currTime := time.Now() if l.logDay != currTime.Day() { l.logDay = currTime.Day() - l.rotateFile(currTime.AddDate(0, 0, -1).Format("2006_01_02")) + l.rotateFile(currTime.AddDate(0, 0, -1).Format("20060102")) // 移除超过保存最长天数的文件 l.removeOldFile(currTime.AddDate(0, 0, -l.maxDay)) } else if fileInfo.Size() >= l.maxSize { - l.rotateFile(currTime.Format("2006_01_02_150405")) + l.rotateFile(currTime.Format("20060102_150405")) } else if time.Since(fileInfo.ModTime()).Hours() > 24 { - l.rotateFile(fileInfo.ModTime().Format("2006_01_02")) + l.rotateFile(fileInfo.ModTime().Format("20060102")) } time.AfterFunc(1*time.Minute, l.checkFile) @@ -100,7 +100,7 @@ func (l *Logger) checkFile() { func (l *Logger) rotateFile(timeFormat string) { l.fileHandle.Close() - newFileName := fmt.Sprintf("%s.%s", l.fileName, timeFormat) + newFileName := fmt.Sprintf("%s-%s", l.fileName, timeFormat) newFilePath := filepath.Join(l.filePath, newFileName) oldfilePath := filepath.Join(l.filePath, l.fileName) @@ -134,14 +134,14 @@ func (l *Logger) removeOldFile(oldFileDate time.Time) { } for _, file := range files { - idx := strings.LastIndex(file.Name(), ".log.") + idx := strings.LastIndex(file.Name(), ".log-") if idx == -1 { continue } - dateStr := file.Name()[idx+5 : idx+15] + dateStr := file.Name()[idx+5 : idx+13] // 解析日期字符串 - fileDate, err := time.Parse("2006_01_02", dateStr) + fileDate, err := time.Parse("20060102", dateStr) if err != nil { l.Errorf("logger RemoveOldFile Parse err: %v", err.Error()) continue From 46e63a88bf8e66a2eefe5b052340dd991036f68d Mon Sep 17 00:00:00 2001 From: TsMask <340112800@qq.com> Date: Mon, 30 Oct 2023 12:05:45 +0800 Subject: [PATCH 2/2] =?UTF-8?q?style:=20=E4=BF=9D=E7=95=99userID=E4=B8=BA1?= =?UTF-8?q?=E7=9A=84=E6=98=AF=E8=B6=85=E7=BA=A7=E7=AE=A1=E7=90=86=E5=91=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/framework/config/config/config.default.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/src/framework/config/config/config.default.yaml b/src/framework/config/config/config.default.yaml index 674c85ad..b864e892 100644 --- a/src/framework/config/config/config.default.yaml +++ b/src/framework/config/config/config.default.yaml @@ -175,7 +175,6 @@ user: # 管理员列表 adminList: - "1" - - "2" # char 字符验证码配置 charCaptcha: