37 lines
662 B
Go
37 lines
662 B
Go
package log
|
|
|
|
import (
|
|
"go.uber.org/zap"
|
|
)
|
|
|
|
var Logger *zap.SugaredLogger
|
|
|
|
var Debug, Info, Warn, Error, Panic func(msg string, keysAndValues ...interface{})
|
|
|
|
func init() {
|
|
|
|
//json logging
|
|
cfg := zap.NewProductionConfig()
|
|
devCfg := zap.NewDevelopmentConfig()
|
|
|
|
// Readable time stamp
|
|
cfg.EncoderConfig.EncodeTime = devCfg.EncoderConfig.EncodeTime
|
|
|
|
// Uncomment to enable debug logging
|
|
// cfg.Level = devCfg.Level
|
|
|
|
logger, err := cfg.Build()
|
|
if err != nil {
|
|
println("unable to intialize zap log")
|
|
panic(err)
|
|
}
|
|
|
|
Logger = logger.Sugar()
|
|
|
|
Debug = Logger.Debugw
|
|
Info = Logger.Infow
|
|
Warn = Logger.Warnw
|
|
Error = Logger.Errorw
|
|
Panic = Logger.Panicw
|
|
}
|