46 lines
800 B
Go
46 lines
800 B
Go
package log
|
|
|
|
import (
|
|
"log"
|
|
|
|
oc "git.loafle.net/overflow/config-go"
|
|
|
|
"go.uber.org/zap"
|
|
)
|
|
|
|
var logger *zap.SugaredLogger
|
|
|
|
func Logger() *zap.SugaredLogger {
|
|
if nil == logger {
|
|
log.Panicf("Initialize Logger first to use Logger")
|
|
}
|
|
return logger
|
|
}
|
|
|
|
func InitializeLogger(configPath string) error {
|
|
var (
|
|
cfg zap.Config
|
|
_logger *zap.Logger
|
|
err error
|
|
)
|
|
|
|
config := oc.New()
|
|
|
|
if err = config.Load(&cfg, configPath); nil != err {
|
|
log.Printf("Loading of logger config has been failed [%v]", err)
|
|
if _logger, err = zap.NewDevelopment(); nil != err {
|
|
return err
|
|
}
|
|
logger = _logger.Sugar()
|
|
logger.Infof("Logger has been initialized as development mode")
|
|
return nil
|
|
}
|
|
|
|
if _logger, err = cfg.Build(); nil != err {
|
|
return err
|
|
}
|
|
logger = _logger.Sugar()
|
|
|
|
return nil
|
|
}
|