- update log
continuous-integration/drone/push Build is passing Details
continuous-integration/drone/tag Build is passing Details

master v1.0.29
李光春 2 years ago
parent 5d338d96aa
commit 54da153cab

@ -80,7 +80,7 @@ func (c *ApiClient) GormMiddleware(ctx context.Context, request gorequest.Respon
})
if err != nil {
if c.config.logDebug == true {
c.logClient.Logger.Sugar().Errorf("[log.GormMiddleware]%s", err.Error())
c.logClient.Errorf(ctx, "[log.GormMiddleware]%s", err.Error())
}
}
}
@ -104,7 +104,7 @@ func (c *ApiClient) GormMiddlewareXml(ctx context.Context, request gorequest.Res
})
if err != nil {
if c.config.logDebug == true {
c.logClient.Logger.Sugar().Errorf("[log.GormMiddlewareXml]%s", err.Error())
c.logClient.Errorf(ctx, "[log.GormMiddlewareXml]%s", err.Error())
}
}
}
@ -128,7 +128,7 @@ func (c *ApiClient) GormMiddlewareCustom(ctx context.Context, api string, reques
})
if err != nil {
if c.config.logDebug == true {
c.logClient.Logger.Sugar().Errorf("[log.GormMiddlewareCustom]%s", err.Error())
c.logClient.Errorf(ctx, "[log.GormMiddlewareCustom]%s", err.Error())
}
}
}

@ -1,3 +1,3 @@
package golog
const Version = "1.0.28"
const Version = "1.0.29"

@ -2,6 +2,7 @@ package golog
import (
"bytes"
"context"
"encoding/json"
"github.com/gin-gonic/gin"
"go.dtapp.net/gojson"
@ -158,7 +159,7 @@ func (c *GinClient) GormMiddleware() gin.HandlerFunc {
})
if err != nil {
if c.config.logDebug == true {
c.logClient.Logger.Sugar().Errorf("[log.gormRecord]%s", err.Error())
c.logClient.Errorf(gotrace_id.SetGinTraceIdContext(context.Background(), ginCtx), err.Error())
}
}
} else {
@ -188,7 +189,7 @@ func (c *GinClient) GormMiddleware() gin.HandlerFunc {
})
if err != nil {
if c.config.logDebug == true {
c.logClient.Logger.Sugar().Errorf("[log.gormRecord]%s", err.Error())
c.logClient.Errorf(gotrace_id.SetGinTraceIdContext(context.Background(), ginCtx), "[log.gormRecord]%s", err.Error())
}
}
}

@ -1,6 +1,7 @@
package golog
import (
"context"
"github.com/natefinch/lumberjack"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
@ -23,7 +24,7 @@ type ZapLogConfig struct {
type ZapLog struct {
config *ZapLogConfig
Logger *zap.Logger
logger *zap.Logger
}
func NewZapLog(config *ZapLogConfig) *ZapLog {
@ -108,12 +109,77 @@ func NewZapLog(config *ZapLogConfig) *ZapLog {
level,
)
zl.Logger = zap.New(core)
zl.logger = zap.New(core)
// 判断是否显示代码行号
if zl.config.ShowLine {
zl.Logger = zl.Logger.WithOptions(zap.AddCaller())
zl.logger = zl.logger.WithOptions(zap.AddCaller())
}
return zl
}
// Panic 记录日志然后panic
func (zl *ZapLog) Panic(ctx context.Context, args ...interface{}) {
zl.logger.Sugar().Panic(args...)
}
// Panicf 记录日志然后panic
func (zl *ZapLog) Panicf(ctx context.Context, template string, args ...interface{}) {
zl.logger.Sugar().Panicf(template, args...)
}
// Fatal 有致命性错误,导致程序崩溃,记录日志,然后退出
func (zl *ZapLog) Fatal(ctx context.Context, args ...interface{}) {
zl.logger.Sugar().Fatal(args...)
}
// Fatalf 有致命性错误,导致程序崩溃,记录日志,然后退出
func (zl *ZapLog) Fatalf(ctx context.Context, template string, args ...interface{}) {
zl.logger.Sugar().Fatalf(template, args...)
}
// Error 错误日志
func (zl *ZapLog) Error(ctx context.Context, args ...interface{}) {
zl.logger.Sugar().Error(args...)
}
// Errorf 错误日志
func (zl *ZapLog) Errorf(ctx context.Context, template string, args ...interface{}) {
zl.logger.Sugar().Errorf(template, args...)
}
// Warn 警告日志
func (zl *ZapLog) Warn(ctx context.Context, args ...interface{}) {
zl.logger.Sugar().Warn(args...)
}
// Warnf 警告日志
func (zl *ZapLog) Warnf(ctx context.Context, template string, args ...interface{}) {
zl.logger.Sugar().Warnf(template, args...)
}
// Info 核心流程日志
func (zl *ZapLog) Info(ctx context.Context, args ...interface{}) {
zl.logger.Sugar().Info(args...)
}
// Infof 核心流程日志
func (zl *ZapLog) Infof(ctx context.Context, template string, args ...interface{}) {
zl.logger.Sugar().Infof(template, args...)
}
// Debug debug日志调试日志
func (zl *ZapLog) Debug(ctx context.Context, args ...interface{}) {
zl.logger.Sugar().Debug(args...)
}
// Debugf debug日志调试日志
func (zl *ZapLog) Debugf(ctx context.Context, template string, args ...interface{}) {
zl.logger.Sugar().Debugf(template, args...)
}
// Trace 粒度超细的,一般情况下我们使用不上
func (zl *ZapLog) Trace(ctx context.Context, args ...interface{}) {
zl.logger.Sugar().Debug(args...)
}

Loading…
Cancel
Save