enhance(log):调整日志系统配置。
This commit is contained in:
parent
2339e4c725
commit
46ae943653
|
@ -62,6 +62,10 @@ func NewLogMiddleware(config LogMiddlewareConfig) fiber.Handler {
|
||||||
fields := []zap.Field{
|
fields := []zap.Field{
|
||||||
zap.Namespace("context"),
|
zap.Namespace("context"),
|
||||||
zap.String("pid", strconv.Itoa(os.Getpid())),
|
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.String("time", stop.Sub(start).String()),
|
||||||
// zap.Object("response", Resp(c.Response())),
|
// zap.Object("response", Resp(c.Response())),
|
||||||
// zap.Object("request", Req(c)),
|
// zap.Object("request", Req(c)),
|
||||||
|
|
|
@ -1,9 +1,12 @@
|
||||||
package logger
|
package logger
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
|
"math"
|
||||||
"os"
|
"os"
|
||||||
|
"time"
|
||||||
|
|
||||||
"gopkg.in/natefinch/lumberjack.v2"
|
"gopkg.in/natefinch/lumberjack.v2"
|
||||||
)
|
)
|
||||||
|
@ -14,10 +17,11 @@ func newRollingWriter() io.Writer {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
now := time.Now()
|
||||||
return &lumberjack.Logger{
|
return &lumberjack.Logger{
|
||||||
Filename: "log/service.log",
|
Filename: fmt.Sprintf("log/service_%s.log", now.Format("2006-01-02_15")),
|
||||||
MaxBackups: 366 * 10, // files
|
MaxBackups: math.MaxInt, // files
|
||||||
MaxSize: 200, // megabytes
|
MaxSize: 200, // megabytes
|
||||||
MaxAge: 366 * 10, // days
|
MaxAge: math.MaxInt, // days
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user