From e8473121a0e641319abbcc3169f933f53eb26a58 Mon Sep 17 00:00:00 2001 From: rexywork Date: Mon, 17 Apr 2023 11:37:27 +0700 Subject: [PATCH 1/3] Add Name() function to Logger struct --- logger.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/logger.go b/logger.go index cd44030d1..3148391b7 100644 --- a/logger.go +++ b/logger.go @@ -281,6 +281,12 @@ func (log *Logger) Core() zapcore.Core { return log.core } +// Name returns the Logger's underlying name. +// Return empty string for unnamed Logger. +func (log *Logger) Name() string { + return log.name +} + func (log *Logger) clone() *Logger { copy := *log return © From 9ebc13aa1245ca9d4d437c0ae24c9d0c5ca10630 Mon Sep 17 00:00:00 2001 From: Sung Yoon Whang Date: Sat, 6 May 2023 18:50:39 -0700 Subject: [PATCH 2/3] Update logger.go Co-authored-by: Abhinav Gupta --- logger.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/logger.go b/logger.go index 3148391b7..0e9548011 100644 --- a/logger.go +++ b/logger.go @@ -281,8 +281,8 @@ func (log *Logger) Core() zapcore.Core { return log.core } -// Name returns the Logger's underlying name. -// Return empty string for unnamed Logger. +// Name returns the Logger's underlying name, +// or an empty string if the logger is unnamed. func (log *Logger) Name() string { return log.name } From 13d49366d0d4321f645234bca2dd64c9ba930490 Mon Sep 17 00:00:00 2001 From: rexywork Date: Sun, 7 May 2023 09:16:52 +0700 Subject: [PATCH 3/3] Add logger name check from Logger object on TestLoggerNames function. Adjust error messages for the test that check Logger Names from Entry. --- logger_test.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/logger_test.go b/logger_test.go index cd5cd20c8..d4af57512 100644 --- a/logger_test.go +++ b/logger_test.go @@ -340,7 +340,8 @@ func TestLoggerNames(t *testing.T) { } log.Info("") require.Equal(t, 1, logs.Len(), "Expected only one log entry to be written.") - assert.Equal(t, tt.expected, logs.AllUntimed()[0].LoggerName, "Unexpected logger name.") + assert.Equal(t, tt.expected, logs.AllUntimed()[0].LoggerName, "Unexpected logger name from entry.") + assert.Equal(t, tt.expected, log.Name(), "Unexpected logger name.") }) withSugar(t, DebugLevel, nil, func(log *SugaredLogger, logs *observer.ObservedLogs) { for _, n := range tt.names { @@ -348,7 +349,8 @@ func TestLoggerNames(t *testing.T) { } log.Infow("") require.Equal(t, 1, logs.Len(), "Expected only one log entry to be written.") - assert.Equal(t, tt.expected, logs.AllUntimed()[0].LoggerName, "Unexpected logger name.") + assert.Equal(t, tt.expected, logs.AllUntimed()[0].LoggerName, "Unexpected logger name from entry.") + assert.Equal(t, tt.expected, log.base.Name(), "Unexpected logger name.") }) } }