package logging import ( "context" "github.com/rs/zerolog" "gorm.io/gorm/logger" "time" ) type DBLogger struct { Logger zerolog.Logger } func (D DBLogger) LogMode(_ logger.LogLevel) logger.Interface { return D } func (D DBLogger) Info(ctx context.Context, s string, i ...interface{}) { D.Logger.Info().Ctx(ctx).Msgf(s, i...) } func (D DBLogger) Warn(ctx context.Context, s string, i ...interface{}) { D.Logger.Warn().Ctx(ctx).Msgf(s, i...) } func (D DBLogger) Error(ctx context.Context, s string, i ...interface{}) { D.Logger.Error().Ctx(ctx).Msgf(s, i...) } func (D DBLogger) Trace(ctx context.Context, begin time.Time, fc func() (sql string, rowsAffected int64), err error) { tupl, rows := fc() D.Logger.Trace().Ctx(ctx). Time("begin", begin). Err(err). Str("sql", tupl). Int64("rows", rows). Msg("Query performed") }