ing
This commit is contained in:
parent
3a7b7e4536
commit
2a89a3c441
21
logging.go
21
logging.go
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user