logging/logging.go
crusader cc5ba36df8 ing
2018-03-20 23:44:19 +09:00

39 lines
800 B
Go

package logging
import (
"log"
"git.loafle.net/commons_go/config"
"go.uber.org/zap"
)
var logger *zap.Logger
func Logger() *zap.Logger {
if nil == logger {
log.Panicf("Logger is not initialized")
}
return logger
}
func InitializeLogger(configPath string) {
var cfg zap.Config
var 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 configp[Development] has been failed [%v]", err)
}
log.Printf("Logger has been initialized as development mode")
return
}
if logger, err = cfg.Build(); nil != err {
log.Panicf("Building of logger config[%s] has been failed [%v]", configPath, err)
}
}