logging/logging.go

36 lines
519 B
Go
Raw Normal View History

2017-08-30 04:03:03 +00:00
package logging
import (
2017-09-11 03:42:00 +00:00
"git.loafle.net/commons_go/config"
2017-08-30 04:03:03 +00:00
2017-08-30 05:00:22 +00:00
"go.uber.org/zap"
2017-08-30 04:03:03 +00:00
)
2017-11-09 06:09:40 +00:00
var logger *zap.Logger
2017-08-30 04:03:03 +00:00
2017-11-09 06:09:40 +00:00
func Logger() *zap.Logger {
2017-11-09 06:09:57 +00:00
if nil == logger {
2017-11-09 06:09:40 +00:00
initializeLogger()
}
return logger
}
func initializeLogger() {
2017-09-19 06:00:20 +00:00
var cfg zap.Config
var err error
2017-09-11 03:42:00 +00:00
conf := config.New()
2017-09-19 06:00:20 +00:00
conf.SetConfigPath("./config")
2017-08-30 04:03:03 +00:00
2017-09-19 06:00:20 +00:00
if err = conf.Load(&cfg, "logging.json"); nil != err {
2017-11-09 06:09:40 +00:00
if logger, err = zap.NewDevelopment(); nil != err {
panic(err)
}
return
2017-08-30 04:03:03 +00:00
}
2017-09-11 03:42:00 +00:00
2017-11-09 06:09:40 +00:00
if logger, err = cfg.Build(); nil != err {
2017-09-11 03:42:00 +00:00
panic(err)
}
2017-08-30 04:03:03 +00:00
}