93 lines
2.0 KiB
Go
93 lines
2.0 KiB
Go
|
|
package log
|
||
|
|
|
||
|
|
import (
|
||
|
|
"datart/config"
|
||
|
|
|
||
|
|
"go.uber.org/zap"
|
||
|
|
"go.uber.org/zap/zapcore"
|
||
|
|
)
|
||
|
|
|
||
|
|
var log *zap.SugaredLogger
|
||
|
|
|
||
|
|
func init() {
|
||
|
|
logConfig := zap.NewProductionEncoderConfig()
|
||
|
|
logConfig.EncodeTime = zapcore.ISO8601TimeEncoder
|
||
|
|
fileEncoder := zapcore.NewJSONEncoder(logConfig)
|
||
|
|
core := zapcore.NewCore(
|
||
|
|
fileEncoder,
|
||
|
|
zapcore.AddSync(config.Conf().LogConf()), // conf is not null
|
||
|
|
// DebugLevel, -1, logs are typically voluminous, and are usually disabled in
|
||
|
|
// production.
|
||
|
|
|
||
|
|
// InfoLevel, 0, is the default logging priority.
|
||
|
|
|
||
|
|
// WarnLevel, 1, logs are more important than Info, but don't need individual
|
||
|
|
// human review.
|
||
|
|
|
||
|
|
// ErrorLevel, 2, logs are high-priority. If an application is running smoothly,
|
||
|
|
// it shouldn't generate any error-level logs.
|
||
|
|
|
||
|
|
// DPanicLevel, 3, logs are particularly important errors. In development the
|
||
|
|
// logger panics after writing the message.
|
||
|
|
|
||
|
|
// PanicLevel, 4, logs a message, then panics.
|
||
|
|
|
||
|
|
// FatalLevel, 5, logs a message, then calls os.Exit(1).
|
||
|
|
config.Conf().LogConf().GetLogLevel(),
|
||
|
|
)
|
||
|
|
|
||
|
|
log = zap.New(core, zap.AddCaller(), zap.AddCallerSkip(1)).Sugar()
|
||
|
|
}
|
||
|
|
|
||
|
|
func Sync() {
|
||
|
|
log.Sync()
|
||
|
|
}
|
||
|
|
|
||
|
|
func Log(lvl zapcore.Level, args ...interface{}) {
|
||
|
|
log.Log(lvl, args...)
|
||
|
|
}
|
||
|
|
|
||
|
|
func Debug(args ...interface{}) {
|
||
|
|
log.Debug(args...)
|
||
|
|
}
|
||
|
|
|
||
|
|
func Info(args ...interface{}) {
|
||
|
|
log.Info(args...)
|
||
|
|
}
|
||
|
|
|
||
|
|
func Warn(args ...interface{}) {
|
||
|
|
log.Warn(args...)
|
||
|
|
}
|
||
|
|
|
||
|
|
func Error(args ...interface{}) {
|
||
|
|
log.Error(args...)
|
||
|
|
}
|
||
|
|
|
||
|
|
func Panic(args ...interface{}) {
|
||
|
|
log.Panic(args...)
|
||
|
|
}
|
||
|
|
|
||
|
|
func Logf(lvl zapcore.Level, template string, args ...interface{}) {
|
||
|
|
log.Logf(lvl, template, args...)
|
||
|
|
}
|
||
|
|
|
||
|
|
func Debugf(template string, args ...interface{}) {
|
||
|
|
log.Debugf(template, args...)
|
||
|
|
}
|
||
|
|
|
||
|
|
func Infof(template string, args ...interface{}) {
|
||
|
|
log.Infof(template, args...)
|
||
|
|
}
|
||
|
|
|
||
|
|
func Warnf(template string, args ...interface{}) {
|
||
|
|
log.Warnf(template, args...)
|
||
|
|
}
|
||
|
|
|
||
|
|
func Errorf(template string, args ...interface{}) {
|
||
|
|
log.Errorf(template, args...)
|
||
|
|
}
|
||
|
|
|
||
|
|
func Panicf(template string, args ...interface{}) {
|
||
|
|
log.Panicf(template, args...)
|
||
|
|
}
|