rezakia / slow-query-logger
A Laravel package to log slow database queries.
v1.0.0
2025-06-28 10:52 UTC
Requires
- php: >=8.0
- illuminate/support: ^8.0|^9.0|^10.0|^11.0
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.
๐ฆ 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