logging/logging.go
crusader 3692aeb915 ing
2017-09-13 12:22:05 +09:00

50 lines
780 B
Go

package logging
import (
"encoding/json"
"flag"
"log"
"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 path1[%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)
}
}