Skip to content

Commit eada6ec

Browse files
authored
Remove log prefix wrapping for json logs (#1451)
1 parent 0c5758e commit eada6ec

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

utils/logging/factory.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,9 @@ func (f *factory) makeLogger(config Config) (Logger, error) {
8787
Compress: config.Compress,
8888
}
8989
fileCore := NewWrappedCore(config.LogLevel, rw, fileEnc)
90+
prefix := config.LogFormat.WrapPrefix(config.MsgPrefix)
9091

91-
l := NewLogger(config.Assertions, config.MsgPrefix, consoleCore, fileCore)
92+
l := NewLogger(config.Assertions, prefix, consoleCore, fileCore)
9293
f.loggers[config.LoggerName] = logWrapper{
9394
logger: l,
9495
displayLevel: consoleCore.AtomicLevel,

utils/logging/format.go

+7
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,13 @@ func (f Format) MarshalJSON() ([]byte, error) {
8080
}
8181
}
8282

83+
func (f Format) WrapPrefix(prefix string) string {
84+
if prefix == "" || f == JSON {
85+
return prefix
86+
}
87+
return fmt.Sprintf("<%s>", prefix)
88+
}
89+
8390
func (f Format) ConsoleEncoder() zapcore.Encoder {
8491
switch f {
8592
case Colors:

utils/logging/log.go

-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ func newZapLogger(prefix string, wrappedCores ...WrappedCore) *zap.Logger {
4141
core := zapcore.NewTee(cores...)
4242
logger := zap.New(core, zap.AddCaller(), zap.AddCallerSkip(2))
4343
if prefix != "" {
44-
prefix := fmt.Sprintf("<%s>", prefix)
4544
logger = logger.Named(prefix)
4645
}
4746

0 commit comments

Comments
 (0)