feat: 添加两个函数,方便调试

This commit is contained in:
tiglog 2023-10-17 21:06:04 +08:00
parent fcba57c4e3
commit 9d7fea4d82

View File

@ -10,6 +10,7 @@ package logger
import ( import (
"fmt" "fmt"
"io" "io"
"net/http"
"os" "os"
"go.uber.org/zap" "go.uber.org/zap"
@ -96,11 +97,12 @@ func ReplaceDefault(l *Logger) { std = l }
func SetLevel(level Level) { std.SetLevel(level) } func SetLevel(level Level) { std.SetLevel(level) }
func With(fields ...Field) { func WithTarget(target string) Field {
std.l.Core().With(fields) return String("target", target)
} }
func WithRequestId(reqId string) {
std.l.Core().With([]Field{String("reqId", reqId)}) func WithRequestId(req *http.Request) Field {
return String("reqId", req.Header.Get("X-Request-ID"))
} }
func Debug(msg string, fields ...Field) { std.Debug(msg, fields...) } func Debug(msg string, fields ...Field) { std.Debug(msg, fields...) }