36 lines
519 B
Go
36 lines
519 B
Go
package logging
|
|
|
|
import (
|
|
"git.loafle.net/commons_go/config"
|
|
|
|
"go.uber.org/zap"
|
|
)
|
|
|
|
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()
|
|
conf.SetConfigPath("./config")
|
|
|
|
if err = conf.Load(&cfg, "logging.json"); nil != err {
|
|
if logger, err = zap.NewDevelopment(); nil != err {
|
|
panic(err)
|
|
}
|
|
return
|
|
}
|
|
|
|
if logger, err = cfg.Build(); nil != err {
|
|
panic(err)
|
|
}
|
|
}
|