dovutuan / lalog
Logging query laravel
Installs: 1
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/dovutuan/lalog
Requires
- php: >=7.4
- illuminate/support: ^7.0|^8.0|^9.0|^10.0|^11.0|^12.0
Requires (Dev)
- mockery/mockery: ^1.6
- orchestra/testbench: ^6.0|^7.0|^8.0|^9.0|^10.0
- phpunit/phpunit: ^12.3
- squizlabs/php_codesniffer: ^3.13
This package is auto-updated.
Last update: 2026-01-12 03:39:31 UTC
README
A simple and efficient Laravel package for logging database queries with automatic file rotation and customizable storage options.
Features
- ๐ Logs all executed queries with bindings and execution time.
- ๐ Daily log files with automatic rotation based on file size.
- โ๏ธ Configurable log storage disk, directory, and formatting.
- ๐ Supports Laravel versions 7.x โ 12.x.
- ๐ Easy integration via Service Provider.
๐ฆ Installation
Install via Composer:
composer require --dev dovutuan/lalog
Publish the configuration file:
php artisan vendor:publish --provider="Dovutuan\Lalog\ServiceProvider" --tag="lalog"
โ๏ธ Configuration
Edit config/lalog.php to customize your logging preferences:
<?php return [ 'enabled' => env('LALOG_QUERY', false), 'disk' => env('LALOG_DISK', 'local'), 'storage' => [ 'directory_path' => env('LALOG_DIRECTORY', 'query-logs'), 'max_file_size_bytes' => env('LALOG_MAX_SIZE', 2097152), // 2MB ], 'formatting' => [ 'log_file_date_format' => 'Y-m-d', // File name format 'query_timestamp_format' => 'Y-m-d H:i:s', // Log entry format ], ];
๐ Basic Usage
Enable query logging by setting the environment variable in your .env file:
LALOG_QUERY=true
That's it! Your Laravel application will now automatically log all database queries.
๐ Sample Output
Query logs will be formatted like this:
---------- QUERY LOG START ----------
Execution Time: 2023-05-15 14:30:45
Duration: 5.2 ms
Query: SELECT * FROM users WHERE id = '1';
---------- QUERY LOG END ----------
๐ Log Rotation
When a log file reaches the maximum size (default 2MB), a new file is automatically created with an incrementing index:
query-logs/
โโโ sql-2023-05-15.sql
โโโ sql-2023-05-15-1.sql
โโโ sql-2023-05-15-2.sql
๐ Advanced Usage
Using the Facade
You can manually record queries using the LaLog facade:
use Dovutuan\Lalog\Facades\LaLog; LaLog::recordQuery($query);
Custom Storage Disk
Configure a custom disk for query logs in config/filesystems.php:
'disks' => [ 'query-logs' => [ 'driver' => 'local', 'root' => storage_path('logs/queries'), ], ],
Then update your .env file:
LALOG_DISK=query-logs
Environment Variables
Available environment variables for configuration:
| Variable | Default | Description |
|---|---|---|
LALOG_QUERY |
false |
Enable/disable query logging |
LALOG_DISK |
local |
Storage disk to use |
LALOG_DIRECTORY |
query-logs |
Directory name for log files |
LALOG_MAX_SIZE |
2097152 |
Maximum file size in bytes (2MB) |
๐งช Testing
Run the test suite:
composer test
๐ค Contributing
Pull requests are welcome! Please see CONTRIBUTING.md for details on how to contribute to this project.
๐ License
This package is open-sourced software licensed under the MIT license.
๐ Issues
If you discover any security vulnerabilities or bugs, please report them via the GitHub Issues page.
๐ Changelog
Please see CHANGELOG.md for more information on what has changed recently.