feat: add gls

This commit is contained in:
2025-12-26 17:11:59 +08:00
parent a538bd6680
commit 5ee1cea0d7
5 changed files with 51 additions and 10 deletions

View File

@@ -8,6 +8,8 @@ import (
"runtime"
"time"
"gitea.com/bitwsd/document_ai/pkg/requestid"
"github.com/rs/zerolog"
"gopkg.in/natefinch/lumberjack.v2"
)
@@ -67,8 +69,13 @@ func log(ctx context.Context, level zerolog.Level, logType LogType, kv ...interf
// 添加日志类型
event.Str("type", string(logType))
// 添加请求ID
if reqID, exists := ctx.Value("request_id").(string); exists {
reqID := requestid.GetRequestID()
if reqID == "" {
if id, exists := ctx.Value("request_id").(string); exists {
reqID = id
}
}
if reqID != "" {
event.Str("request_id", reqID)
}
@@ -149,4 +156,3 @@ func Fatal(ctx context.Context, kv ...interface{}) {
func Access(ctx context.Context, kv ...interface{}) {
log(ctx, zerolog.InfoLevel, TypeAccess, kv...)
}