This commit is contained in:
crusader 2018-03-20 23:44:19 +09:00
parent 851f39a83d
commit cc5ba36df8

View File

@ -1,6 +1,8 @@
package logging
import (
"log"
"git.loafle.net/commons_go/config"
"go.uber.org/zap"
@ -10,26 +12,27 @@ var logger *zap.Logger
func Logger() *zap.Logger {
if nil == logger {
initializeLogger()
log.Panicf("Logger is not initialized")
}
return logger
}
func initializeLogger() {
func InitializeLogger(configPath string) {
var cfg zap.Config
var err error
conf := config.New()
conf.SetConfigPath("./config")
if err = conf.Load(&cfg, "logging.json"); nil != err {
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 {
panic(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 {
panic(err)
log.Panicf("Building of logger config[%s] has been failed [%v]", configPath, err)
}
}