增加包装的DB Client

This commit is contained in:
zhangdeman committed 2021-12-24 16:00:48 +08:00
1 parent 9daa1ba251
commit 0faf50ceba
2 files changed
+128 -27

No files matched your search

+25 -4
View File
@@ -12,6 +12,8 @@ import (
"fmt"
"time"
"github.com/gin-gonic/gin"
"gorm.io/gorm"
"go.uber.org/zap/zapcore"
@@ -47,15 +49,34 @@ func NewGormV2(loggerLevel zapcore.Level, consoleOutput bool, encoder zapcore.En
}, nil
}
// NewGormLoggerWithInstance 获取gorm日志实现
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 3:36 PM 2021/12/24
func NewGormLoggerWithInstance(ctx *gin.Context, instance *zap.Logger, node string, extraCtxFieldList []string) logger.Interface {
return &Gorm{
instance: instance,
traceIDField: "",
extraCtxFieldList: extraCtxFieldList,
flag: "",
node: node,
ctx: ctx,
}
}
// Gorm v2 版本库日志实现
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 9:55 下午 2021/3/1
type Gorm struct {
instance *zap.Logger // 日志实例
traceIDField string // 串联请求上下文的的ID
flag string // 数据库标识
instance *zap.Logger // 日志实例
traceIDField string // 串联请求上下文的的ID
extraCtxFieldList []string // 从请求上线问提取的字段
flag string // 数据库标识
node string // 数据库节点 master / slave
ctx *gin.Context // gin上下文
}
// LogMode ...
@@ -145,7 +166,7 @@ func (g *Gorm) getTraceID(ctx context.Context) string {
return fmt.Sprintf("%v", ctx.Value(g.traceIDField))
}
// GetGormSQL 获取tracefn
// GetGormSQL 获取trace fn
//
// Author : go_developer@163.com<白茶清欢>
//
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.