ing
This commit is contained in:
parent
2a89a3c441
commit
71ae3a62af
29
logging.go
29
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
|
||||
}
|
||||
|
|
14
logging_test.go
Normal file
14
logging_test.go
Normal file
|
@ -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")
|
||||
}
|
Loading…
Reference in New Issue
Block a user