brandworks / querylogger
在 Laravel 4 中追踪或记录您的(慢)查询
v1.0.0
2016-01-05 15:14 UTC
Requires
- php: >=5.4.0
- laravel/framework: 4.2.*
This package is not auto-updated.
Last update: 2024-09-18 19:04:31 UTC
README
此包允许您记录和追踪您的查询。例如:如果您有一些慢查询,您可以找到它们被调用的位置。
要求
- PHP >=5.4
- LARAVEL 4.2
开始使用
Laravel 4.2
-
安装
brandworks/querylogger
包$ composer require brandworks/querylogger
-
更新 app/config/app.php` 以激活包
# Add `Brandworks\Querylogger\QueryloggerServiceProvider` to the `providers` array 'providers' => array( ... 'Brandworks\Querylogger\QueryloggerServiceProvider', ) # You do not need to add the alias - This is being handled for you in the service provider
-
发布配置文件
$ php artisan config:publish brandworks/querylogger
-
可选地,您可以更改选项
您还可以向应用程序中添加一个路由,以便直接在表格中查看日志
-
在配置中:将 add_route 和 store_serialized 选项设置为 true
# file: app/config/packages/brandworks/querylogger/config.php 'store_serialized' => false, 'add_route' => false,
-
您可以可选地设置查看查询的路线
# file: app/config/packages/brandworks/querylogger/config.php 'route' => 'queries',
我不建议在实时环境中启用此功能;一旦访客找到路由,他们就可以查看您的查询并推断出您的数据库结构!
因此,如果您要添加路由,请在本地配置文件中这样做。
使用方法
以下是此包的简单使用示例
//this does not affect user load since this is done in app finish (the client did already receive response) App::finish(function($request, $response) { //make sure the package is enabled -- prevent errors if(class_exists("QueryLogger")) { $queryLog = QueryLogger::getLog(); Log::info('The query log', $queryLog); //or do some other stuff with the log so you can make it more readale/filter on query time/... } }
贡献
欢迎贡献。
待办事项
- 编写测试
许可
此项目受 MIT 许可协议条款的约束。