feat: 升级日志

This commit is contained in:
2025-10-31 12:29:01 +08:00
parent 1b81309d82
commit fe1986e938
3 changed files with 4 additions and 46 deletions

View File

@ -12,8 +12,6 @@ import (
"os" "os"
"time" "time"
"git.zhangdeman.cn/zhangdeman/consts"
"github.com/pkg/errors" "github.com/pkg/errors"
"go.uber.org/zap" "go.uber.org/zap"

View File

@ -10,18 +10,13 @@ package wrapper
import ( import (
"context" "context"
"git.zhangdeman.cn/zhangdeman/consts"
"git.zhangdeman.cn/zhangdeman/logger" "git.zhangdeman.cn/zhangdeman/logger"
"go.uber.org/zap" "go.uber.org/zap"
"go.uber.org/zap/zapcore" "go.uber.org/zap/zapcore"
) )
// NewGinLogger 使用gin框架记录日志 // NewGinLogger 使用gin框架记录日志
// func NewGinLogger(loggerLevel logger.LogLevel, consoleOutput bool, encoder zapcore.Encoder, splitConfig *logger.RotateLogConfig, extractFieldList []string, skip int) (*Gin, error) {
// Author : go_developer@163.com<白茶清欢>
//
// Date : 3:45 下午 2021/1/3
func NewGinLogger(loggerLevel consts.LogLevel, consoleOutput bool, encoder zapcore.Encoder, splitConfig *logger.RotateLogConfig, extractFieldList []string, skip int) (*Gin, error) {
var ( var (
err error err error
l *zap.Logger l *zap.Logger
@ -41,20 +36,12 @@ func NewGinLogger(loggerLevel consts.LogLevel, consoleOutput bool, encoder zapco
} }
// Gin 包装gin实例 // Gin 包装gin实例
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 3:59 下午 2021/1/3
type Gin struct { type Gin struct {
loggerInstance *zap.Logger // zap 的日志实例 loggerInstance *zap.Logger // zap 的日志实例
extractFieldList []string // 从gin中抽取的字段 extractFieldList []string // 从gin中抽取的字段
} }
// formatFieldList 格式化日志field列表 // formatFieldList 格式化日志field列表
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 4:13 下午 2021/1/3
func (gw *Gin) formatFieldList(ctx context.Context, inputFieldList []zap.Field) []zap.Field { func (gw *Gin) formatFieldList(ctx context.Context, inputFieldList []zap.Field) []zap.Field {
if nil == ctx { if nil == ctx {
ctx = context.Background() ctx = context.Background()
@ -70,70 +57,42 @@ func (gw *Gin) formatFieldList(ctx context.Context, inputFieldList []zap.Field)
} }
// Debug 日志 // Debug 日志
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 4:14 下午 2021/1/3
func (gw *Gin) Debug(ctx context.Context, msg string, field ...zap.Field) { func (gw *Gin) Debug(ctx context.Context, msg string, field ...zap.Field) {
fieldList := gw.formatFieldList(ctx, field) fieldList := gw.formatFieldList(ctx, field)
gw.loggerInstance.Debug(msg, fieldList...) gw.loggerInstance.Debug(msg, fieldList...)
} }
// Info 日志 // Info 日志
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 4:28 下午 2021/1/3
func (gw *Gin) Info(ctx context.Context, msg string, field ...zap.Field) { func (gw *Gin) Info(ctx context.Context, msg string, field ...zap.Field) {
fieldList := gw.formatFieldList(ctx, field) fieldList := gw.formatFieldList(ctx, field)
gw.loggerInstance.Info(msg, fieldList...) gw.loggerInstance.Info(msg, fieldList...)
} }
// Warn 日志 // Warn 日志
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 4:29 下午 2021/1/3
func (gw *Gin) Warn(ctx context.Context, msg string, field ...zap.Field) { func (gw *Gin) Warn(ctx context.Context, msg string, field ...zap.Field) {
fieldList := gw.formatFieldList(ctx, field) fieldList := gw.formatFieldList(ctx, field)
gw.loggerInstance.Warn(msg, fieldList...) gw.loggerInstance.Warn(msg, fieldList...)
} }
// Error 日志 // Error 日志
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 4:29 下午 2021/1/3
func (gw *Gin) Error(ctx context.Context, msg string, field ...zap.Field) { func (gw *Gin) Error(ctx context.Context, msg string, field ...zap.Field) {
fieldList := gw.formatFieldList(ctx, field) fieldList := gw.formatFieldList(ctx, field)
gw.loggerInstance.Error(msg, fieldList...) gw.loggerInstance.Error(msg, fieldList...)
} }
// Panic 日志 // Panic 日志
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 4:29 下午 2021/1/3
func (gw *Gin) Panic(ctx context.Context, msg string, field ...zap.Field) { func (gw *Gin) Panic(ctx context.Context, msg string, field ...zap.Field) {
fieldList := gw.formatFieldList(ctx, field) fieldList := gw.formatFieldList(ctx, field)
gw.loggerInstance.Panic(msg, fieldList...) gw.loggerInstance.Panic(msg, fieldList...)
} }
// DPanic 日志 // DPanic 日志
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 4:30 下午 2021/1/3
func (gw *Gin) DPanic(ctx context.Context, msg string, field ...zap.Field) { func (gw *Gin) DPanic(ctx context.Context, msg string, field ...zap.Field) {
fieldList := gw.formatFieldList(ctx, field) fieldList := gw.formatFieldList(ctx, field)
gw.loggerInstance.DPanic(msg, fieldList...) gw.loggerInstance.DPanic(msg, fieldList...)
} }
// GetZapLoggerInstance 获取zap日志实例 // GetZapLoggerInstance 获取zap日志实例
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 2021/01/03 22:56:47
func (gw *Gin) GetZapLoggerInstance() *zap.Logger { func (gw *Gin) GetZapLoggerInstance() *zap.Logger {
return gw.loggerInstance return gw.loggerInstance
} }

View File

@ -10,14 +10,15 @@ package logger
import ( import (
"bytes" "bytes"
"fmt" "fmt"
"git.zhangdeman.cn/zhangdeman/consts"
"git.zhangdeman.cn/zhangdeman/serialize"
"io" "io"
"log" "log"
"net/http" "net/http"
"strings" "strings"
"sync" "sync"
"time" "time"
"git.zhangdeman.cn/zhangdeman/consts"
"git.zhangdeman.cn/zhangdeman/serialize"
) )
func NewZincLogConnect(cfg *ZincConfig) io.Writer { func NewZincLogConnect(cfg *ZincConfig) io.Writer {