webikevn / query-logger
一个用于记录Laravel应用程序所有查询的开发工具。
1.0
2020-09-29 17:17 UTC
Requires
- laravel/framework: ~5.5||~6.0||~7.0||~8.0
This package is auto-updated.
Last update: 2024-09-29 06:25:41 UTC
README
📝 这是一个用于记录Laravel应用程序所有查询的开发工具。
安装
$ composer require webikevn/query-logger --dev
当LOG_QUERY
设置为true
时,Query Logger将被启用。
请保留
--dev
选项。
用法
$ 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
...
配置
如果您想在某个环境中使用它,您可以通过配置文件控制是否记录查询:
config/logging.php
return [ //... 'query' => [ 'enabled' => env('LOG_QUERY', false), // Only record queries that are slower than the following time // Unit: milliseconds 'slower_than' => 0, ], ];