logging/logging.go

43 lines
620 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
"encoding/json"
"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
)
type loggerKeyType int
const loggerKey loggerKeyType = iota
2017-09-11 03:42:00 +00:00
var Logger *zap.Logger
2017-08-30 04:03:03 +00:00
func init() {
2017-09-11 03:42:00 +00:00
conf := config.New()
conf.SetConfigName("logging")
conf.SetConfigType("json")
2017-09-13 03:24:16 +00:00
conf.AddConfigPath(".")
conf.AddConfigPath("./config")
2017-09-11 03:42:00 +00:00
err := conf.ReadInConfig()
if nil != err {
panic(err)
2017-08-30 05:00:22 +00:00
}
2017-08-30 04:03:03 +00:00
2017-09-11 03:42:00 +00:00
buf, err := conf.Marshal("json")
if err != nil {
panic(err)
2017-08-30 04:03:03 +00:00
}
2017-09-11 03:42:00 +00:00
var cfg zap.Config
if err = json.Unmarshal(buf, &cfg); err != nil {
panic(err)
2017-08-30 04:03:03 +00:00
}
2017-09-11 03:42:00 +00:00
Logger, err = cfg.Build()
if err != nil {
panic(err)
}
2017-08-30 04:03:03 +00:00
}