日志升级相关枚举值定义

This commit is contained in:
2024-11-25 16:33:16 +08:00
parent 98eb52ae30
commit eab7bab9d7
7 changed files with 114 additions and 66 deletions

View File

@ -30,7 +30,7 @@ import (
// Author : go_developer@163.com<白茶清欢>
//
// Date : 9:56 下午 2021/3/1
func NewGormV2(loggerLevel string, consoleOutput bool, encoder zapcore.Encoder, splitConfig *logger2.RotateLogConfig, traceIDField string, skip int) (logger.Interface, error) {
func NewGormV2(loggerLevel consts.LogLevel, consoleOutput bool, encoder zapcore.Encoder, splitConfig *logger2.RotateLogConfig, traceIDField string, skip int) (logger.Interface, error) {
logConfList := []logger2.SetLoggerOptionFunc{logger2.WithEncoder(encoder), logger2.WithCallerSkip(skip), logger2.WithCaller()}
if consoleOutput {
logConfList = append(logConfList, logger2.WithConsoleOutput())
@ -165,7 +165,7 @@ func (g *Gorm) Trace(ctx context.Context, begin time.Time, fc func() (string, in
// Author : go_developer@163.com<白茶清欢>
//
// Date : 4:11 PM 2021/12/24
func (g *Gorm) write(ctx context.Context, message string, level string, data map[string]any) {
func (g *Gorm) write(ctx context.Context, message string, level consts.LogLevel, data map[string]any) {
if len(message) == 0 {
message = "SQL执行记录"
}
@ -186,21 +186,9 @@ func (g *Gorm) write(ctx context.Context, message string, level string, data map
if nil == g.outCtx {
g.outCtx = context.Background()
}
/*for _, extraField := range g.extraCtxFieldList {
if len(extraField) == 0 {
continue
}
val := g.outCtx.Value(extraField)
if nil == val {
val = ""
}
if val, exist := data[extraField]; !exist || nil == val {
data[extraField] = val
}
}*/
dataList := logger2.ZapLogDataList(logger2.NewLogData(g.outCtx, consts.LogTypeDatabase, "", data))
switch strings.ToUpper(level) {
switch level {
case consts.LogLevelDebug:
g.instance.Debug(message, dataList...)
case consts.LogLevelInfo:

View File

@ -9,6 +9,7 @@ package wrapper
import (
"context"
"git.zhangdeman.cn/zhangdeman/consts"
"git.zhangdeman.cn/zhangdeman/logger"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
@ -19,7 +20,7 @@ import (
// Author : go_developer@163.com<白茶清欢>
//
// Date : 3:45 下午 2021/1/3
func NewGinLogger(loggerLevel string, consoleOutput bool, encoder zapcore.Encoder, splitConfig *logger.RotateLogConfig, extractFieldList []string, skip int) (*Gin, error) {
func NewGinLogger(loggerLevel consts.LogLevel, consoleOutput bool, encoder zapcore.Encoder, splitConfig *logger.RotateLogConfig, extractFieldList []string, skip int) (*Gin, error) {
var (
err error
l *zap.Logger