Skip to content

Commit

Permalink
Enhance db.Scan with ParamsFilter - Issue 7336 - Suggestion (#7337)
Browse files Browse the repository at this point in the history
  • Loading branch information
evyaffe authored Jan 12, 2025
1 parent 8503287 commit fed4923
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions logger/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ var (
})
// Recorder logger records running SQL into a recorder instance
Recorder = traceRecorder{Interface: Default, BeginAt: time.Now()}

// RecorderParamsFilter defaults to no-op, allows to be run-over by a different implementation
RecorderParamsFilter = func(ctx context.Context, sql string, params ...interface{}) (string, []interface{}) {
return sql, params
}
)

// New initialize logger
Expand Down Expand Up @@ -211,3 +216,10 @@ func (l *traceRecorder) Trace(ctx context.Context, begin time.Time, fc func() (s
l.SQL, l.RowsAffected = fc()
l.Err = err
}

func (l *traceRecorder) ParamsFilter(ctx context.Context, sql string, params ...interface{}) (string, []interface{}) {
if RecorderParamsFilter == nil {
return sql, params
}
return RecorderParamsFilter(ctx, sql, params...)
}

0 comments on commit fed4923

Please sign in to comment.