Skip to content

fix slogLogger to support ParameterizedQueries Config#7574

Merged
jinzhu merged 1 commit intogo-gorm:masterfrom
EricWvi:fix-slogLogger
Sep 8, 2025
Merged

fix slogLogger to support ParameterizedQueries Config#7574
jinzhu merged 1 commit intogo-gorm:masterfrom
EricWvi:fix-slogLogger

Conversation

@EricWvi
Copy link
Copy Markdown
Contributor

@EricWvi EricWvi commented Aug 31, 2025

  • Do only one thing
  • Non breaking API changes
  • Tested

What did this pull request do?

Add ParamsFilter method to slogLogger

User Case Description

After update, logger.NewSlogLogger supports ParameterizedQueries. Now, it has no effect.

@propel-code-bot
Copy link
Copy Markdown
Contributor

propel-code-bot bot commented Aug 31, 2025

This pull request introduces a ParamsFilter method to the slogLogger implementation in the logger package. The new method enables slogLogger to respect the ParameterizedQueries configuration option, ensuring that SQL parameters are filtered out from logs when this config is enabled, in alignment with other logger implementations.

This summary was automatically generated by @propel-code-bot

Comment thread logger/slog.go
Comment on lines +92 to +98
// ParamsFilter filter params
func (l *slogLogger) ParamsFilter(ctx context.Context, sql string, params ...interface{}) (string, []interface{}) {
if l.Parameterized {
return sql, nil
}
return sql, params
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[BestPractice]

[CodeDuplication] The ParamsFilter method is nearly identical to the existing implementation in logger/logger.go. The only difference is the field name (l.Parameterized vs l.Config.ParameterizedQueries). Consider extracting this logic to a shared utility function or ensuring consistent field naming across logger implementations to avoid code duplication.

@EricWvi
Copy link
Copy Markdown
Contributor Author

EricWvi commented Aug 31, 2025

Hi, @jinzhu @rezamokaram. Please take a look.

@EricWvi
Copy link
Copy Markdown
Contributor Author

EricWvi commented Aug 31, 2025

ref.

gorm/logger/logger.go

Lines 193 to 198 in cace4a6

func (l *logger) ParamsFilter(ctx context.Context, sql string, params ...interface{}) (string, []interface{}) {
if l.Config.ParameterizedQueries {
return sql, nil
}
return sql, params
}

@jinzhu jinzhu merged commit 4087ac7 into go-gorm:master Sep 8, 2025
27 checks passed
mackinleysmith pushed a commit to mackinleysmith/gorm that referenced this pull request Sep 8, 2025
@rezamokaram
Copy link
Copy Markdown
Contributor

Thanks for your attention and contribution.
@EricWvi

phroggyy pushed a commit to incident-io/gorm that referenced this pull request Jan 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants