rezakia/slow-query-logger

A Laravel package to log slow database queries.

v1.0.0 2025-06-28 10:52 UTC

This package is auto-updated.

Last update: 2025-06-28 12:31:17 UTC


README

A Laravel package to log slow SQL queries for performance analysis and debugging.

Packagist Version License

๐Ÿ“ฆ Installation

You can install the package via Composer:

composer require rezakia/slow-query-logger

โš™๏ธ Configuration

You can publish the config file with:

php artisan vendor:publish --tag=slow-query-logger-config

This is the content of the published config file:

return [
'enabled' => true,
'threshold_ms' => 100, // Minimum time (in ms) for a query to be considered slow
'log_path' => storage_path('logs/slow-queries.log'),
];

๐Ÿงช Testing

Run tests using:

./vendor/bin/phpunit | php artisan test

Or if using Testbench:

vendor/bin/testbench

๐Ÿš€ Usage

Once installed, the package automatically logs slow queries. You can view them in the log file specified in your config.

Each log entry contains:

User ID (or guest)

Request method and URL

Route name

SQL query and bindings

Execution time

โœ… Example Log

[2025-06-28 11:12:13]
User: 1 | IP: 127.0.0.1 | Method: GET | URL: http://localhost/users | Route: users.index
Slow Query (350ms): SELECT * FROM users WHERE email = ? | Bindings: ["test@example.com"]
--------------------------------------------------------------------------------------

๐Ÿ“„ License

MIT ยฉ Reza Kiamanesh

  • rezakiamanesh
  • reza kia