diff --git a/logging.go b/logging.go index d2f8c64..b9f392a 100644 --- a/logging.go +++ b/logging.go @@ -6,9 +6,16 @@ import ( "go.uber.org/zap" ) -var Logger *zap.Logger +var logger *zap.Logger -func init() { +func Logger() *zap.Logger { + if nil != logger { + initializeLogger() + } + return logger +} + +func initializeLogger() { var cfg zap.Config var err error @@ -16,10 +23,13 @@ func init() { conf.SetConfigPath("./config") if err = conf.Load(&cfg, "logging.json"); nil != err { - panic(err) + if logger, err = zap.NewDevelopment(); nil != err { + panic(err) + } + return } - if Logger, err = cfg.Build(); nil != err { + if logger, err = cfg.Build(); nil != err { panic(err) } }