bkwld / reporter
生成包含应用程序时间、内存使用、输入数据和SQL查询的Laravel 4请求的样式日志
3.1.0
2017-04-04 23:35 UTC
Requires
- php: >=5.3.0
- illuminate/support: ^5.0
Conflicts
- laravel/framework: <5.4.0
README
Reporter是一个用于Laravel 5(版本3.x)和Laravel 4(版本2.x)的包,它恢复了Laravel 3分析器中的功能。它不是在浏览器中显示输出,而是将其写入磁盘中的日志文件,您可以使用tail -f
或类似Mac的Console等应用程序实时查看这些日志文件。这比基于浏览器的分析器有一些优势
- 您可以检查AJAX请求
- POST变量会被记录
- 输出渲染不受您的应用程序CSS或JS的影响
- 您可以检查处于生产环境中的应用程序
输出看起来像
---------------------------------------------------------------------
1/28/16 1:21:09 AM
REQUEST: /admin/articles/19/edit?search=example
TIME: 111.46ms
TIMERS:
example: 2.36ms
MEMORY: 14 MB (PEAK: 14 MB)
INPUT:
search: example
SQL: 5 queries
(0.46 ms) select * from `admins` where `admins`.`id` = '1' limit 1
(0.30 ms) select * from `articles` where `articles`.`id` = '19' limit 1
(0.44 ms) select * from `images` where `images`.`imageable_id` in ('19') and
`images`.`imageable_type` = 'App\Article'
(0.49 ms) select * from `articles` where `articles`.`id` = '19' limit 1
(0.43 ms) select * from `images` where `images`.`imageable_id` in ('19') and
`images`.`imageable_type` = 'App\Article'
INFO: Hey, make sure to wear pants
或者,如果您启用了样式
Reporter还添加了计时代码块的能力(如示例中的"TIMERS"行所示)。
安装
- 将Reporter添加到composer.json:
"bkwld/reporter": "~3.0",
然后执行composer install。 - 将
'Bkwld\Reporter\ServiceProvider',
添加到您的app/config/app.php的providers数组中。 - 如果您打算使用计时器,请将
'Timer' => 'Bkwld\Reporter\Facades\Timer',
添加到app/config/app.php的aliases数组中。
配置
enable
- 如果为false,Reporter将不会做任何事情。默认情况下,如果将包的配置文件发布到您的app/config目录,则此设置为false。style
- 为终端中的输出添加颜色和样式代码error_log
- 如果为true,也会将日志写入PHP的error_log()
levels
- 应显示的日志级别的数组ignore
- 一个正则表达式字符串。如果请求路径匹配,则不会写入任何日志。
使用
日志记录
Reporter将其日志写入app/storage/logs/reporter.log。我建议从项目目录运行tail -f storage/logs/reporter.log
以跟踪它。
计时器
Laravel 3通过其分析器来计时事件。Reporter重新引入了这一功能。
Timer::start('example');
// Some code that you are benchmarking
Timer::stop('example');
start()和stop()以其参数作为字符串,用于匹配开始和停止调用。它也显示为日志中计时器的键。上面的示例会将类似这样的行添加到日志中
TIMERS:
example: 20.02ms