ing
This commit is contained in:
parent
851f39a83d
commit
cc5ba36df8
15
logging.go
15
logging.go
|
@ -1,6 +1,8 @@
|
||||||
package logging
|
package logging
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"log"
|
||||||
|
|
||||||
"git.loafle.net/commons_go/config"
|
"git.loafle.net/commons_go/config"
|
||||||
|
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
|
@ -10,26 +12,27 @@ var logger *zap.Logger
|
||||||
|
|
||||||
func Logger() *zap.Logger {
|
func Logger() *zap.Logger {
|
||||||
if nil == logger {
|
if nil == logger {
|
||||||
initializeLogger()
|
log.Panicf("Logger is not initialized")
|
||||||
}
|
}
|
||||||
return logger
|
return logger
|
||||||
}
|
}
|
||||||
|
|
||||||
func initializeLogger() {
|
func InitializeLogger(configPath string) {
|
||||||
var cfg zap.Config
|
var cfg zap.Config
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
conf := config.New()
|
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 {
|
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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if logger, err = cfg.Build(); nil != err {
|
if logger, err = cfg.Build(); nil != err {
|
||||||
panic(err)
|
log.Panicf("Building of logger config[%s] has been failed [%v]", configPath, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user