bytetcore / lalog
A robust Laravel SQL Query Logger that logs all database queries to files with rotation, performance metrics, and cross-database compatibility.
Requires
- php: ^8.0
- illuminate/database: ^9.0|^10.0|^11.0|^12.0|^13.0
- illuminate/filesystem: ^9.0|^10.0|^11.0|^12.0|^13.0
- illuminate/support: ^9.0|^10.0|^11.0|^12.0|^13.0
Requires (Dev)
- laravel/pint: 1.0
- orchestra/testbench: ^7.0|^8.0|^9.0|^10.0|^11.0
- phpunit/phpunit: ^9.5|^10.0|^11.0|^12.0|^13.0
This package is auto-updated.
Last update: 2026-04-03 09:33:28 UTC
README
Automatically log all SQL queries to files with binding interpolation, time tracking, and file rotation support. Perfect for debugging and performance analysis during development.
Features
- 🔍 Full SQL Logging — Captures every query with bindings interpolated
- ⏱️ Query Time — Records execution time for each query
- 📁 File Rotation — Automatically creates new files when size limit is reached
- 🗑️ Auto Clear — Optionally clears previous logs each request cycle
- ⚙️ Configurable — Disk, directory, format, max size, extension — all customizable
- 🚀 Zero Config — Works out of the box with sensible defaults
Requirements
- PHP 8.0+
- Laravel 9.x+
Installation
composer require bytetcore/lalog --dev
The package auto-discovers its ServiceProvider. No manual registration needed.
Publish Config (Optional)
php artisan vendor:publish --tag=lalog-config
Configuration
Add to your .env:
APP_LOG_QUERY=true
Available Options
| Option | Env Variable | Default | Description |
|---|---|---|---|
enabled |
APP_LOG_QUERY |
false |
Enable/disable query logging |
disk |
LALOG_DISK |
local |
Storage disk (any disk from filesystems.php) |
directory |
LALOG_DIRECTORY |
query |
Directory within the disk |
max_size |
LALOG_MAX_SIZE |
2000000 |
Max file size in bytes (~2MB) |
format |
LALOG_FORMAT |
sql-{date} |
File name format ({date} placeholder) |
date_format |
LALOG_DATE_FORMAT |
Y-m-d |
PHP date format for {date} |
extension |
LALOG_EXTENSION |
sql |
File extension |
clear_on_start |
LALOG_CLEAR_ON_START |
true |
Delete current day's log on start |
Example Config
// config/lalog.php return [ 'enabled' => env('APP_LOG_QUERY', false), 'disk' => env('LALOG_DISK', 'local'), 'directory' => env('LALOG_DIRECTORY', 'query'), 'max_size' => env('LALOG_MAX_SIZE', 2000000), 'format' => env('LALOG_FORMAT', 'sql-{date}'), 'date_format' => env('LALOG_DATE_FORMAT', 'Y-m-d'), 'extension' => env('LALOG_EXTENSION', 'sql'), 'clear_on_start' => env('LALOG_CLEAR_ON_START', true), ];
Output Example
File: storage/app/query/sql-2026-04-03.sql
----------START--------- Date: 2026-04-03 13:45:12 Time query: 2.34(ms) select * from `users` where `email` = 'john@example.com' limit 1; ----------END---------- Date: 2026-04-03 13:45:12 Time query: 0.89(ms) select * from `posts` where `user_id` = '1' order by `created_at` desc; ----------END----------
File Rotation
When a log file exceeds max_size, new files are created with an incremented index:
query/sql-2026-04-03.sql (2MB reached)
query/sql-2026-04-03-1.sql (next file)
query/sql-2026-04-03-2.sql (and so on)
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Credits
See AUTHORS for the list of contributors.
License
Licensed under the Apache License 2.0. Please see License File for more information.