2018-08-22 07:29:27 +00:00
|
|
|
package log
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
|
|
|
|
oc "git.loafle.net/overflow/config-go"
|
|
|
|
|
|
|
|
"go.uber.org/zap"
|
|
|
|
)
|
|
|
|
|
2018-08-22 08:17:22 +00:00
|
|
|
var logger *zap.Logger
|
2018-08-22 07:29:27 +00:00
|
|
|
|
2018-08-22 08:17:22 +00:00
|
|
|
func Logger() *zap.Logger {
|
2018-08-22 07:29:27 +00:00
|
|
|
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
|
|
|
|
}
|
2018-08-22 08:17:22 +00:00
|
|
|
logger = _logger
|
|
|
|
logger.Info("Logger has been initialized as development mode")
|
2018-08-22 07:29:27 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
if _logger, err = cfg.Build(); nil != err {
|
|
|
|
return err
|
|
|
|
}
|
2018-08-22 08:17:22 +00:00
|
|
|
logger = _logger
|
2018-08-22 07:29:27 +00:00
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|