This commit is contained in:
crusader 2017-09-19 15:00:20 +09:00
parent 805ddec62e
commit e489d57791
2 changed files with 8 additions and 26 deletions

View File

@ -1,5 +1,4 @@
package: git.loafle.net/commons_go/logging
import:
- package: go.uber.org/zap
version: v1.5.0
- package: git.loafle.net/commons_go/config
- package: go.uber.org/zap

View File

@ -1,42 +1,25 @@
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 {
var err error
conf := config.New()
conf.SetConfigPath("./config")
if err = conf.Load(&cfg, "logging.json"); nil != err {
panic(err)
}
Logger, err = cfg.Build()
if err != nil {
if Logger, err = cfg.Build(); nil != err {
panic(err)
}
}