overtrue / laravel-query-logger
用于记录 Laravel 应用所有查询的开发工具。
3.2.0
2024-02-23 20:09 UTC
Requires
- laravel/framework: ^9.0|^10.0|^11.0
Requires (Dev)
- brainmaestro/composer-git-hooks: dev-master
- laravel/pint: ^1.5
README
📝 用于记录 Laravel 应用所有查询的开发工具。
安装
$ composer require overtrue/laravel-query-logger -vvv
当 LOG_QUERY
设置为 true
时,Laravel Query Logger 将被启用。
用法
$ 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', 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'), // Log Channel 'channel' => 'stack', ], ];
❤️ 赞助我
如果你喜欢我的项目并想支持它,点击这里 ❤️
项目由 JetBrains 支持
非常感谢 JetBrains 好意提供许可证,让我可以在此和其他开源项目上工作。
PHP 扩展包开发
想知道如何从零开始构建 PHP 扩展包?
请关注我的实战课程,我会在此课程中分享一些扩展开发经验 —— 《PHP 扩展包实战教程 - 从入门到发布》
许可协议
MIT