Skip to content

Do not log queries which are faster than 100ms by default #3435

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 26, 2025

Conversation

ildyria
Copy link
Member

@ildyria ildyria commented Jun 11, 2025

So we can focus on the slow queries.

This pull request introduces a feature to filter SQL query logging based on execution time, enhancing the application's debugging capabilities while reducing unnecessary log noise. The changes include adding a configuration option for a minimum query execution time and updating the logging logic accordingly.

Enhancements to SQL query logging:

  • app/Providers/AppServiceProvider.php: Updated the logSQL method to skip logging SQL queries that execute faster than the configured minimum time (log_sql_min_time). This prevents logging insignificant queries.

  • config/database.php: Added a new configuration option, log_sql_min_time, which allows setting a minimum execution time (in milliseconds) for SQL queries to be logged. This provides more control over the volume of logged queries.

@ildyria ildyria added the Review: easy Easy review expected: probably just need a quick to go through. label Jun 11, 2025
@ildyria ildyria requested a review from a team as a code owner June 11, 2025 08:32
Copy link

codecov bot commented Jun 11, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 86.38%. Comparing base (51f335c) to head (ffcb421).
Report is 37 commits behind head on master.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@@ -199,6 +199,11 @@ private function logSQL(QueryExecuted $query): void
return;
}

// if the query is not slow enough, we do not log it.
if ($query->time < config('database.log_sql_min_time', 100)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Add info 100 is ms

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed ffcb421

| executed very fast and are not relevant for debugging.
|
*/
'log_sql_min_time' => (int) env('DB_LOG_SQL_MIN_TIME', 100),
Copy link
Contributor

Choose a reason for hiding this comment

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

Add info 100 is ms

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed ffcb421

@ildyria ildyria merged commit d46169a into master Jun 26, 2025
35 checks passed
@ildyria ildyria deleted the improve-sql-logging branch June 26, 2025 06:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Review: easy Easy review expected: probably just need a quick to go through.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants