logging/logging.go
crusader 805ddec62e ing
2017-09-13 12:24:16 +09:00

43 lines
620 B
Go

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)
}
}