From 46ae943653d4f4e87aed8ba069d83779c51fbca3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=90=E6=B6=9B?= Date: Mon, 12 Jun 2023 17:09:13 +0800 Subject: [PATCH] =?UTF-8?q?enhance(log):=E8=B0=83=E6=95=B4=E6=97=A5?= =?UTF-8?q?=E5=BF=97=E7=B3=BB=E7=BB=9F=E9=85=8D=E7=BD=AE=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- logger/middleware.go | 4 ++++ logger/rolling.go | 12 ++++++++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/logger/middleware.go b/logger/middleware.go index 52a170f..d826810 100644 --- a/logger/middleware.go +++ b/logger/middleware.go @@ -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)), diff --git a/logger/rolling.go b/logger/rolling.go index be8ff61..960dd4c 100644 --- a/logger/rolling.go +++ b/logger/rolling.go @@ -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 } }