package logging import ( "encoding/json" "git.loafle.net/commons_go/config" "go.uber.org/zap" ) type loggerKeyType int const loggerKey loggerKeyType = iota var Logger *zap.Logger func init() { conf := config.New() conf.SetConfigName("logging") conf.SetConfigType("json") conf.AddConfigPath(".") conf.AddConfigPath("./config") err := conf.ReadInConfig() if nil != err { panic(err) } buf, err := conf.Marshal("json") if err != nil { panic(err) } var cfg zap.Config if err = json.Unmarshal(buf, &cfg); err != nil { panic(err) } Logger, err = cfg.Build() if err != nil { panic(err) } }