Global logger (#2265)

* global logger

* return global logger appliance instead of inner logger

* fix lint issues

* global logger test
pull/2274/head
realityone 2 years ago committed by GitHub
parent 57dee517e5
commit f0c2a6ed90
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      log/global.go
  2. 2
      log/global_test.go

@ -27,8 +27,8 @@ func (a *loggerAppliance) SetLogger(in Logger) {
a.Logger = in a.Logger = in
} }
func (a *loggerAppliance) GetLogger() Logger { func (a *loggerAppliance) Log(level Level, keyvals ...interface{}) error {
return a.Logger return a.Logger.Log(level, keyvals...)
} }
// SetLogger should be called before any other log call. // 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. // GetLogger returns global logger appliance as logger in current process.
func GetLogger() Logger { func GetLogger() Logger {
return global.GetLogger() return global
} }
// Log Print log by level and keyvals. // Log Print log by level and keyvals.

@ -14,7 +14,7 @@ func TestGlobalLog(t *testing.T) {
logger := NewStdLogger(buffer) logger := NewStdLogger(buffer)
SetLogger(logger) SetLogger(logger)
if GetLogger() != logger { if global.Logger != logger {
t.Error("GetLogger() is not equal to logger") t.Error("GetLogger() is not equal to logger")
} }

Loading…
Cancel
Save