diff --git a/logging.go b/logging.go index b90223f..e05e5d4 100644 --- a/logging.go +++ b/logging.go @@ -8,31 +8,38 @@ import ( "go.uber.org/zap" ) -var logger *zap.Logger +var logger *zap.SugaredLogger -func Logger() *zap.Logger { +func Logger() *zap.SugaredLogger { if nil == logger { log.Panicf("Initialize Logger first to use Logger") } return logger } -func InitializeLogger(configPath string) { - var cfg zap.Config - var err error +func InitializeLogger(configPath string) error { + var ( + cfg zap.Config + _logger *zap.Logger + err error + ) conf := config.New() if err = conf.Load(&cfg, configPath); nil != err { log.Printf("Loading of logger config has been failed [%v]", err) - if logger, err = zap.NewDevelopment(); nil != err { - log.Panicf("Building of logger config[Development] has been failed [%v]", err) + if _logger, err = zap.NewDevelopment(); nil != err { + return err } - logger.Info("Logger has been initialized as development mode") - return + logger = _logger.Sugar() + logger.Infof("Logger has been initialized as development mode") + return nil } - if logger, err = cfg.Build(); nil != err { - log.Panicf("Building of logger config[%s] has been failed [%v]", configPath, err) + if _logger, err = cfg.Build(); nil != err { + return err } + logger = _logger.Sugar() + + return nil } diff --git a/logging_test.go b/logging_test.go new file mode 100644 index 0000000..e7118d9 --- /dev/null +++ b/logging_test.go @@ -0,0 +1,14 @@ +package logging + +import ( + "log" + "testing" +) + +func TestInitializeLogger(t *testing.T) { + if err := InitializeLogger(""); nil != err { + log.Panicf("Failed %v", err) + } + + logger.Infof("Logger has been initialized") +}