This commit is contained in:
crusader 2018-03-21 18:32:10 +09:00
parent 3a7b7e4536
commit 2a89a3c441

View File

@ -1,8 +1,6 @@
package logging
import (
"flag"
"fmt"
"log"
"git.loafle.net/commons_go/config"
@ -10,33 +8,22 @@ import (
"go.uber.org/zap"
)
var (
configPath *string
)
func init() {
configPath = flag.String("log-config-path", "./logging.json", "The path of logger config file")
flag.Parse()
}
var logger *zap.Logger
func Logger() *zap.Logger {
if nil == logger {
initializeLogger()
logger.Info(fmt.Sprintf("Logger has been initialized. config[%s]", *configPath))
log.Panicf("Initialize Logger first to use Logger")
}
return logger
}
func initializeLogger() {
func InitializeLogger(configPath string) {
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 config[Development] has been failed [%v]", err)
@ -46,6 +33,6 @@ func initializeLogger() {
}
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)
}
}