From f0c2a6ed90d1eca00a0adbc667249c401a029cae Mon Sep 17 00:00:00 2001 From: realityone Date: Thu, 11 Aug 2022 11:32:10 +0800 Subject: [PATCH] Global logger (#2265) * global logger * return global logger appliance instead of inner logger * fix lint issues * global logger test --- log/global.go | 6 +++--- log/global_test.go | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/log/global.go b/log/global.go index f75b07e64..624fccb39 100644 --- a/log/global.go +++ b/log/global.go @@ -27,8 +27,8 @@ func (a *loggerAppliance) SetLogger(in Logger) { a.Logger = in } -func (a *loggerAppliance) GetLogger() Logger { - return a.Logger +func (a *loggerAppliance) Log(level Level, keyvals ...interface{}) error { + return a.Logger.Log(level, keyvals...) } // SetLogger should be called before any other log call. @@ -39,7 +39,7 @@ func SetLogger(logger Logger) { // GetLogger returns global logger appliance as logger in current process. func GetLogger() Logger { - return global.GetLogger() + return global } // Log Print log by level and keyvals. diff --git a/log/global_test.go b/log/global_test.go index 04bb19c51..16aa67738 100644 --- a/log/global_test.go +++ b/log/global_test.go @@ -14,7 +14,7 @@ func TestGlobalLog(t *testing.T) { logger := NewStdLogger(buffer) SetLogger(logger) - if GetLogger() != logger { + if global.Logger != logger { t.Error("GetLogger() is not equal to logger") }