Skip to content

Commit 6bfec6c

Browse files
committed
log: Fix logger name duplication in zap adapter
1 parent 58e8a11 commit 6bfec6c

2 files changed

Lines changed: 22 additions & 2 deletions

File tree

framework/log/log.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,21 @@ func (l *Logger) log(debug bool, s string) {
251251
// Logging is disabled - do nothing.
252252
}
253253

254+
func (l *Logger) logNameOverwrite(loggerName string, debug bool, s string) {
255+
if loggerName == "" {
256+
loggerName = l.Name
257+
}
258+
if loggerName != "" {
259+
s = loggerName + ": " + s
260+
}
261+
262+
out := l.output()
263+
out.Write(time.Now(), debug, s)
264+
265+
// Logging is disabled - do nothing.
266+
}
267+
268+
254269
func (l *Logger) Sublogger(name string) *Logger {
255270
if l.Name != "" && name != "" {
256271
name = l.Name + "/" + name

framework/log/zap.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,14 @@ func (l zapLogger) Write(entry zapcore.Entry, fields []zapcore.Field) error {
4646
f.AddTo(enc)
4747
}
4848
if entry.LoggerName != "" {
49-
l.L.Name += "/" + entry.LoggerName
49+
l.L.logNameOverwrite(
50+
l.L.Name+"/"+entry.LoggerName,
51+
entry.Level == zapcore.DebugLevel,
52+
l.L.formatMsg(entry.Message, enc.Fields),
53+
)
54+
} else {
55+
l.L.log(entry.Level == zapcore.DebugLevel, l.L.formatMsg(entry.Message, enc.Fields))
5056
}
51-
l.L.log(entry.Level == zapcore.DebugLevel, l.L.formatMsg(entry.Message, enc.Fields))
5257
return nil
5358
}
5459

0 commit comments

Comments
 (0)