logging/logging.go
crusader 5db5cb3f2d ing
2018-03-20 23:55:46 +09:00

48 lines
867 B
Go

package logging
import (
"flag"
"log"
"git.loafle.net/commons_go/config"
"go.uber.org/zap"
)
var (
configPath *string
)
func init() {
configPath = flag.String("logger-config-path", "./logging.json", "The path of logger config file")
flag.Parse()
}
var logger *zap.Logger
func Logger() *zap.Logger {
if nil == logger {
initializeLogger()
}
return logger
}
func initializeLogger() {
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 config[Development] has been failed [%v]", err)
}
return
}
if logger, err = cfg.Build(); nil != err {
log.Panicf("Building of logger config[%s] has been failed [%v]", *configPath, err)
}
}