overtrue/laravel-query-logger
Requirements
- PHP 8.3 or newer
- Laravel 13
Version 6 drops Laravel 12 support. Applications on Laravel 12 should use ^5.1.
The logging API and configuration are unchanged.
Installing
$ composer require overtrue/laravel-query-logger -vvv
Laravel Query Logger will be enabled when LOG_QUERY is true.
Usage
$ tail -f ./storage/logs/laravel.log
[2017-09-05 14:52:14] local.DEBUG: [800μs] select count(*) as aggregate from `discussions` where `discussions`.`deleted_at` is null | GET: http://laravel.app/discussions
[2017-09-05 14:52:14] local.DEBUG: [1.07ms] select * from `discussions` where `discussions`.`deleted_at` is null order by `is_top` desc, `created_at` desc limit 15 offset 0 | GET: http://laravel.app/discussions
[2017-09-05 14:52:14] local.DEBUG: [3.63s] select `tags`.*, `taggables`.`taggable_id` as `pivot_taggable_id`, `taggables`.`tag_id` as `pivot_tag_id` from `tags` inner join `taggables` on `tags`.`id` = `taggables`.`tag_id` where `taggables`.`taggable_id` in ('1', '2', '3', '4', '5', '6', '7', '8') and `taggables`.`taggable_type` = 'App\\Models\\Discussion' order by `order_column` asc | GET: http://laravel.app/discussions
[2017-09-05 14:52:14] local.DEBUG: [670μs] select * from `users` where `users`.`id` in ('1', '2', '4') and `users`.`deleted_at` is null | GET: http://laravel.app/discussions
...
Configuration
You can also control whether to log a query via the configuration file:
config/logging.php:
return [
//...
'query' => [
'enabled' => env('LOG_QUERY', env('APP_ENV') === 'local'),
// Only record queries that are slower than the following time
// Unit: milliseconds
'slower_than' => 0,
// Only record queries when the QUERY_LOG_TRIGGER is set in the environment,
// or when the trigger HEADER, GET, POST, or COOKIE variable is set.
'trigger' => env('QUERY_LOG_TRIGGER'),
// Except record queries
'except' => [
// '*_telescope_*',
],
// Log Channel
'channel' => 'stack',
],
];
:heart: Sponsor me
如果你喜欢我的项目并想支持它,点击这里 :heart:
Project supported by JetBrains
Many thanks to Jetbrains for kindly providing a license for me to work on this and other open-source projects.
License
MIT
Related Packages
doctrine/dbal
Powerful PHP database abstraction layer (DBAL) with many features for database s...
644,549,754
9,698
laravel/serializable-closure
Laravel Serializable Closure provides an easy and secure way to serialize closur...
423,477,751
607
nunomaduro/collision
Cli error handling for console/command-line PHP applications.
399,241,428
4,660
Version History
| Version | Released | PHP | Laravel | License |
|---|---|---|---|---|
| v6.0.0 | ^8.3 | ^13.0 | MIT | |
| v5.1.0 | ^12.0| | MIT | ||
| v5.0.0 | ^13.0 | MIT | ||
| v4.0.0 | ^12.0| | MIT | ||
| 3.4.0 | ^9.0| | MIT | ||
| 3.3.0 | ^9.0| | MIT | ||
| 3.2.0 | ^9.0| | MIT | ||
| 3.1.0 | ^9.0| | MIT | ||
| 3.0.0 | ^9.0 | MIT | ||
| 2.1.4 | ~5.5| | MIT | ||
| 2.1.3 | ~5.5| | MIT | ||
| 2.1.2 | ~5.5| | MIT | ||
| 2.1.1 | ~5.5| | MIT | ||
| 2.1.0 | ~5.5| | MIT | ||
| 2.0.1 | ~5.5| | MIT | ||
| 2.0.0 | ^5.5.0| | MIT | ||
| 1.2.0 | ~5.5| | MIT | ||
| 1.1.0 | ~5.5| | MIT | ||
| 1.0.8 | ~5.5| | MIT | ||
| 1.0.7 | ~5.5| | MIT | ||
| 1.0.6 | ~5.5| | MIT | ||
| 1.0.5 | 5.* | MIT | ||
| 1.0.4 | 5.* | MIT | ||
| 1.0.3 | 5.* | MIT | ||
| 1.0.2 | 5.* | MIT | ||
| 1.0.1 | 5.* | MIT | ||
| 1.0.0 | 5.* | MIT |