u
This commit is contained in:
1 parent
b9f728812d
commit
d9b2522552
12 files changed
+104
-19
No files matched your search
@@ -1,17 +1,21 @@
|
||||
package middleware
|
||||
|
||||
import (
|
||||
"cn/oneao/base-go/logx"
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/cloudwego/hertz/pkg/app"
|
||||
"github.com/cloudwego/hertz/pkg/common/hlog"
|
||||
"github.com/hertz-contrib/requestid"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
func Log() app.HandlerFunc {
|
||||
return func(c context.Context, ctx *app.RequestContext) {
|
||||
reqId := requestid.Get(ctx)
|
||||
|
||||
c = context.WithValue(c, "RequestID", reqId)
|
||||
|
||||
start := time.Now() // 记录开始时间
|
||||
|
||||
// 执行后续处理
|
||||
@@ -20,8 +24,7 @@ func Log() app.HandlerFunc {
|
||||
// 计算耗时
|
||||
duration := time.Since(start).Milliseconds()
|
||||
|
||||
hlog.Info("请求完成",
|
||||
zap.String("RequestID", requestid.Get(ctx)),
|
||||
logx.CtxInfo(c, "请求完成",
|
||||
zap.String("IP", ctx.ClientIP()),
|
||||
zap.String("Method", string(ctx.Method())),
|
||||
zap.String("Path", string(ctx.Path())),
|
||||
|
||||
Reference in new issue
Block a user