logging/logging.go
crusader 18bb52405c ing
2017-09-13 12:14:20 +09:00

49 lines
772 B
Go

package logging
import (
"encoding/json"
"flag"
"git.loafle.net/commons_go/config"
"go.uber.org/zap"
)
type loggerKeyType int
const loggerKey loggerKeyType = iota
var Logger *zap.Logger
func init() {
configPath := flag.String("config", ".", "The path of config")
flag.Parse()
log.Printf("logging: config path[%s]", *configPath)
conf := config.New()
conf.SetConfigName("logging")
conf.SetConfigType("json")
conf.AddConfigPath(*configPath)
// 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)
}
}