From 5db5cb3f2ddd304c27dac5aa6b74d6aa47c2fdc9 Mon Sep 17 00:00:00 2001 From: crusader Date: Tue, 20 Mar 2018 23:55:46 +0900 Subject: [PATCH] ing --- logging.go | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/logging.go b/logging.go index b7dd865..f6e6dc1 100644 --- a/logging.go +++ b/logging.go @@ -1,6 +1,7 @@ package logging import ( + "flag" "log" "git.loafle.net/commons_go/config" @@ -8,31 +9,39 @@ import ( "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 { - log.Panicf("Logger is not initialized") + initializeLogger() } return logger } -func InitializeLogger(configPath string) { +func initializeLogger() { var cfg zap.Config var err error conf := config.New() - if err = conf.Load(&cfg, configPath); 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 { - log.Panicf("Building of logger configp[Development] has been failed [%v]", err) + log.Panicf("Building of logger config[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) + log.Panicf("Building of logger config[%s] has been failed [%v]", *configPath, err) } }