iris 系列文章 封装 logrus 日志

func Init() {
    initLog()    // 普通日志
    initAlipay() //支付宝日志
    initOrder()  //订单日志
    initWechat() //微信日志
}

var Log *logrus.Logger

func initLog() {
    logpath := config.GetConf().Log.LoggerPath
    logname := config.GetConf().Log.LoggerFiles.Logger
    _ = util.CreateFile(logpath)
    hook := lfshook.NewHook(lfshook.PathMap{
        logrus.InfoLevel:  filepath.Join(logpath, logname) + ".log",
        logrus.ErrorLevel: filepath.Join(logpath, logname) + ".err.log",
        logrus.WarnLevel:  filepath.Join(logpath, logname) + ".debug.log",
    }, &logrus.JSONFormatter{TimestampFormat: "2006-01-02 15:04:05"})
    Log = logrus.New()
    Log.Hooks.Add(hook)
    Log.Out = ioutil.Discard
}

// WithField 结构化字段写入
func WithField(key string, value interface{}) *logrus.Entry {
    return Log.WithFields(map[string]interface{}{key: value})
}

func WithFields(fields map[string]interface{}) *logrus.Entry {
    return Log.WithFields(fields)
}

by JeffreyBool blog :point_right: link

kenuo
讨论数量: 0
(= ̄ω ̄=)··· 暂无内容!

请勿发布不友善或者负能量的内容。与人为善,比聪明更重要!