enhance(log):调整日志系统配置。

This commit is contained in:
徐涛 2023-06-12 17:09:13 +08:00
parent 2339e4c725
commit 46ae943653
2 changed files with 12 additions and 4 deletions

View File

@ -62,6 +62,10 @@ func NewLogMiddleware(config LogMiddlewareConfig) fiber.Handler {
fields := []zap.Field{
zap.Namespace("context"),
zap.String("pid", strconv.Itoa(os.Getpid())),
zap.String("method", c.Method()),
zap.String("remote", c.IP()),
zap.Strings("forwarded", c.IPs()),
zap.String("url", c.OriginalURL()),
zap.String("time", stop.Sub(start).String()),
// zap.Object("response", Resp(c.Response())),
// zap.Object("request", Req(c)),

View File

@ -1,9 +1,12 @@
package logger
import (
"fmt"
"io"
"log"
"math"
"os"
"time"
"gopkg.in/natefinch/lumberjack.v2"
)
@ -14,10 +17,11 @@ func newRollingWriter() io.Writer {
return nil
}
now := time.Now()
return &lumberjack.Logger{
Filename: "log/service.log",
MaxBackups: 366 * 10, // files
MaxSize: 200, // megabytes
MaxAge: 366 * 10, // days
Filename: fmt.Sprintf("log/service_%s.log", now.Format("2006-01-02_15")),
MaxBackups: math.MaxInt, // files
MaxSize: 200, // megabytes
MaxAge: math.MaxInt, // days
}
}