Jianghan hai 1 ano
pai
achega
1c21933253
Modificáronse 1 ficheiros con 6 adicións e 5 borrados
  1. 6 5
      log/log.go

+ 6 - 5
log/log.go

@@ -51,14 +51,15 @@ func getzapLevel(level string) zapcore.Level {
 	}
 }
 
-func newLogWriter(logpath string, maxsize int, compress bool) io.Writer {
+func newLogWriter(logpath string, maxsize, maxbacks int, compress bool) io.Writer {
 	if logpath == "" || logpath == "-" {
 		return os.Stdout
 	}
 	return &lumberjack.Logger{
-		Filename: logpath,
-		MaxSize:  maxsize,
-		Compress: compress,
+		Filename:   logpath,
+		MaxSize:    maxsize,
+		MaxBackups: maxbacks,
+		Compress:   compress,
 	}
 }
 
@@ -80,7 +81,7 @@ func newZapEncoder() zapcore.EncoderConfig {
 	return encoderConfig
 }
 func newLoggerCore(log *logConfig) zapcore.Core {
-	hook := newLogWriter(log.LogPath, log.MaxSize, log.Compress)
+	hook := newLogWriter(log.LogPath, log.MaxSize, log.MaxBackups, log.Compress)
 
 	encoderConfig := newZapEncoder()