Skip to content

Add support for disabling GORM slow query logging#276

Closed
Copilot wants to merge 6 commits into
masterfrom
copilot/disable-slow-log-output
Closed

Add support for disabling GORM slow query logging#276
Copilot wants to merge 6 commits into
masterfrom
copilot/disable-slow-log-output

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Nov 22, 2025

GORM logs queries exceeding 200ms by default. Users have no way to suppress these logs in production environments where large policy sets trigger false-positive warnings.

Changes

New API:

  • NewAdapterWithConfig(driverName, dataSourceName, config, params...) - Constructor accepting custom gorm.Config
  • NewConfigWithoutSlowQueryLog() - Helper returning silent logger config

Internal:

  • Added gormConfig field to Adapter struct
  • Modified openDBConnection() to accept variadic config parameter
  • Extracted parseAdapterParams() to reduce duplication between constructors

Usage

// Disable slow query logs
config := gormadapter.NewConfigWithoutSlowQueryLog()
a, _ := gormadapter.NewAdapterWithConfig("mysql", "user:pass@tcp(127.0.0.1:3306)/", config)

// Or custom logger level
config := &gorm.Config{
    Logger: logger.Default.LogMode(logger.Error),
}
a, _ := gormadapter.NewAdapterWithConfig("postgres", "...", config, "dbname")

Existing NewAdapter() calls remain unchanged - this is additive only.

Original prompt

This section details on the original issue you should resolve

<issue_title>How can I disable the slow log output</issue_title>
<issue_description>Hi
How can I disable the slow log output:

dev-tintin-system authz-deployment-7786685fcd-xp7cp authz-service 2025/11/22 03:04:01 /go/pkg/mod/github.com/casbin/gorm-adapter/v3@v3.37.0/adapter.go:505 SLOW SQL >= 200ms
dev-tintin-system authz-deployment-7786685fcd-xp7cp authz-service [1275.311ms] [rows:63851] SELECT * FROM "casbin_rule" ORDER BY ID
```</issue_description>

## Comments on the Issue (you are @copilot in this section)

<comments>
</comments>


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@CLAassistant
Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@nomeguy nomeguy marked this pull request as ready for review November 22, 2025 08:49
Copilot AI and others added 4 commits November 22, 2025 08:55
Co-authored-by: nomeguy <85475922+nomeguy@users.noreply.github.com>
Co-authored-by: nomeguy <85475922+nomeguy@users.noreply.github.com>
Co-authored-by: nomeguy <85475922+nomeguy@users.noreply.github.com>
Co-authored-by: nomeguy <85475922+nomeguy@users.noreply.github.com>
Copilot AI changed the title [WIP] Disable slow log output in authz service Add support for disabling GORM slow query logging Nov 22, 2025
Copilot AI requested a review from nomeguy November 22, 2025 09:03
@nomeguy
Copy link
Copy Markdown

nomeguy commented Nov 22, 2025

@copilot don't add so complicated code, just disable the slow log directly and entirely, no need to add config option.

and no need to add go test

Co-authored-by: nomeguy <85475922+nomeguy@users.noreply.github.com>
@nomeguy nomeguy closed this Nov 22, 2025
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.

How can I disable the slow log output

3 participants