From c05d669c5fa567605d39b6acf9c904132ab588b3 Mon Sep 17 00:00:00 2001 From: zhengkunwang223 Date: Tue, 20 Dec 2022 16:48:20 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E6=94=B9log=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E7=9A=84=E5=8E=8B=E7=BC=A9=E6=A0=BC=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/init/log/log.go | 3 +-- backend/log/writer.go | 6 +++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/backend/init/log/log.go b/backend/init/log/log.go index 38164f1a8..6d31f916d 100644 --- a/backend/init/log/log.go +++ b/backend/init/log/log.go @@ -16,7 +16,7 @@ import ( const ( TimeFormat = "2006-01-02 15:04:05" - FileTImeFormat = "2006-01-02-15-04-05" + FileTImeFormat = "2006-01-02" RollingTimePattern = "0 0 * * *" ) @@ -28,7 +28,6 @@ func Init() { } func setOutput(logger *logrus.Logger, config configs.LogConfig) { - writer, err := log.NewWriterFromConfig(&log.Config{ LogPath: config.Path, FileName: config.LogName, diff --git a/backend/log/writer.go b/backend/log/writer.go index 698482c38..0e1194d15 100644 --- a/backend/log/writer.go +++ b/backend/log/writer.go @@ -120,7 +120,7 @@ func NewWriterFromConfig(c *Config) (RollingWriter, error) { } fileName := c.FileName - if strings.Contains(fi.Name(), fileName) && strings.Contains(fi.Name(), c.LogSuffix+".tar.gz") { + if strings.Contains(fi.Name(), fileName) && strings.Contains(fi.Name(), c.LogSuffix+".gz") { start := strings.Index(fi.Name(), "-") end := strings.Index(fi.Name(), c.LogSuffix) name := fi.Name() @@ -259,11 +259,11 @@ func (w *Writer) Reopen(file string) error { func (w *Writer) CompressFile(logFile string) error { op := files.NewFileOp() - comFileName := path.Base(logFile) + ".tar.gz" + comFileName := path.Base(logFile) + ".gz" filePath := path.Dir(logFile) fmt.Println(path.Dir(logFile)) - if err := op.Compress([]string{logFile}, filePath, comFileName, files.TarGz); err != nil { + if err := op.Compress([]string{logFile}, filePath, comFileName, files.Gz); err != nil { return err } if errR := os.Remove(logFile); errR != nil {