feat: support customize of log keys (#5103)

This commit is contained in:
Qiying Wang
2025-08-20 20:11:45 +08:00
committed by GitHub
parent 73d6fcfccd
commit 20f56ae1d0
4 changed files with 133 additions and 8 deletions

View File

@@ -277,6 +277,7 @@ func SetUp(c LogConf) (err error) {
// Need to wait for the first caller to complete the execution.
setupOnce.Do(func() {
setupLogLevel(c)
setupLogKey(c.LogKey)
if !c.Stat {
DisableStat()
@@ -579,3 +580,30 @@ func writeStack(msg string) {
func writeStat(msg string) {
getWriter().Stat(msg, mergeGlobalFields(addCaller())...)
}
func setupLogKey(c logKeyConf) {
if c.CallerKey != "" {
callerKey = c.CallerKey
}
if c.ContentKey != "" {
contentKey = c.ContentKey
}
if c.DurationKey != "" {
durationKey = c.DurationKey
}
if c.LevelKey != "" {
levelKey = c.LevelKey
}
if c.SpanKey != "" {
spanKey = c.SpanKey
}
if c.TimestampKey != "" {
timestampKey = c.TimestampKey
}
if c.TraceKey != "" {
traceKey = c.TraceKey
}
if c.TruncatedKey != "" {
truncatedKey = c.TruncatedKey
}
}