Gorm

gorm自制日志

May 8, 2024
Go, Gorm, Mysql, Log

第三方包 # gorm.io/gorm/logger 示例 # package boot import ( "context" "fmt" "io/ioutil" "log" "os" "time" "github.com/xiaohubai/alpha/config" "go.uber.org/zap" "gorm.io/gorm/logger" "gorm.io/gorm/utils" ) type cfg struct { SlowThreshold time.Duration Colorful bool LogLevel logger.LogLevel } type traceRecorder struct { logger.Interface BeginAt time.Time SQL string RowsAffected int64 Err error } func (t traceRecorder) New() *traceRecorder { return &traceRecorder{Interface: t.Interface, BeginAt: time.Now()} } func (t *traceRecorder) Trace(ctx context.Context, begin time.Time, fc func() (string, int64), err error) { t. ...