mll-lab / laravel-query-log
Log database queries to an output channel of your choice
Installs: 19 115
Dependents: 0
Suggesters: 0
Security: 0
Stars: 3
Watchers: 2
Forks: 1
Open Issues: 0
Requires
- php: ^7.2 || ^8
- illuminate/contracts: 5.6.* || 5.7.* || 5.8.* || ^6 || ^7 || ^8 || ^9
Requires (Dev)
- ergebnis/composer-normalize: ^2.26
- mll-lab/php-cs-fixer-config: ^4.4
- nunomaduro/larastan: ^0.4 || ^0.5 || ^0.6 || ^1
- orchestra/database: 3.6.* || 3.7.* || 3.8.* || 3.9.* || ^4 || ^5 || ^6 || ^7
- orchestra/testbench: 3.6.* || 3.7.* || 3.8.* || 3.9.* || ^4 || ^5 || ^6
README
You can easily implement what this package does by adding something like this to DatabaseServerProvider::boot()
:
if (env('APP_DEBUG')) { DB::listen(function (QueryExecuted $query): void { $sql = str_replace("\n", ' ', $query->sql); $bindings = \Safe\json_encode($query->bindings); \Safe\file_put_contents( filename: storage_path('logs/query.log'), data: "SQL: {$sql} ||| Bindings: {$bindings} ||| Time: {$query->time}ms\n", flags: FILE_APPEND, ); }); }
laravel-query-log
Log database queries to an output channel of your choice.
Installation
composer require mll-lab/laravel-query-log
That's it. Laravel's package discovery will automatically kick in.
Configuration
All database queries are written to storage/logs/query.log
by default.
If you want to change the location, publish the configuration file:
php artisan vendor:publish --tag=query-log-config