u
This commit is contained in:
1 parent
6277fb2f9e
commit
8ecac0d7dd
270 files changed
+40438
-529
No files matched your search
@@ -0,0 +1,59 @@
|
||||
package logx
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/cloudwego/hertz/pkg/common/hlog"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
// getRequestID 从 context 中取 RequestID,如果没有则返回空字符串
|
||||
func getRequestID(ctx context.Context) string {
|
||||
if ctx == nil {
|
||||
return ""
|
||||
}
|
||||
if rid, ok := ctx.Value("RequestID").(string); ok {
|
||||
return rid
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func CtxInfo(ctx context.Context, v ...interface{}) {
|
||||
rid := getRequestID(ctx)
|
||||
if rid != "" {
|
||||
v = append(v, zap.String("RequestID", rid))
|
||||
}
|
||||
hlog.Info(v...)
|
||||
}
|
||||
|
||||
func CtxError(ctx context.Context, v ...interface{}) {
|
||||
rid := getRequestID(ctx)
|
||||
if rid != "" {
|
||||
v = append(v, zap.String("RequestID", rid))
|
||||
}
|
||||
hlog.Error(v...)
|
||||
}
|
||||
|
||||
func CtxWarn(ctx context.Context, v ...interface{}) {
|
||||
rid := getRequestID(ctx)
|
||||
if rid != "" {
|
||||
v = append(v, zap.String("RequestID", rid))
|
||||
}
|
||||
hlog.Warn(v...)
|
||||
}
|
||||
|
||||
func CtxDebug(ctx context.Context, v ...interface{}) {
|
||||
rid := getRequestID(ctx)
|
||||
if rid != "" {
|
||||
v = append(v, zap.String("RequestID", rid))
|
||||
}
|
||||
hlog.Debug(v...)
|
||||
}
|
||||
|
||||
func CtxFatal(ctx context.Context, v ...interface{}) {
|
||||
rid := getRequestID(ctx)
|
||||
if rid != "" {
|
||||
v = append(v, zap.String("RequestID", rid))
|
||||
}
|
||||
hlog.Fatal(v...)
|
||||
}
|
||||
Reference in new issue
Block a user