Laravel Debugbar
Installation
Require this package with composer:
composer require barryvdh/laravel-debugbar
After updating composer, add the ServiceProvider to the providers array in config/app.php
If you use a catch-all/fallback route, make sure you load the Debugbar ServiceProvider before your own App ServiceProviders.
Laravel 5.x:
Barryvdh\Debugbar\ServiceProvider::class,
If you want to use the facade to log messages, add this to your facades in app.php:
'Debugbar' => Barryvdh\Debugbar\Facade::class,
The profiler is enabled by default, if you have app.debug=true. You can override that in the config (debugbar.enabled
). See more options in config/debugbar.php
You can also set in your config if you want to include/exclude the vendor files also (FontAwesome, Highlight.js and jQuery). If you already use them in your site, set it to false. You can also only display the js or css vendors, by setting it to 'js' or 'css'. (Highlight.js requires both css + js, so set to true
for syntax highlighting)
Copy the package config to your local config with the publish command:
php artisan vendor:publish --provider="Barryvdh\Debugbar\ServiceProvider"
Lumen:
For Lumen, register a different Provider in bootstrap/app.php
:
if (env('APP_DEBUG')) {
$app->register(Barryvdh\Debugbar\LumenServiceProvider::class);
}
To change the configuration, copy the file to your config folder and enable it:
$app->configure('debugbar');
Usage
You can now add messages using the Facade (when added), using the PSR-3 levels (debug, info, notice, warning, error, critical, alert, emergency):
Debugbar::info($object);
Debugbar::error('Error!');
Debugbar::warning('Watch out…');
Debugbar::addMessage('Another message', 'mylabel');
And start/stop timing:
Debugbar::startMeasure('render','Time for rendering');
Debugbar::stopMeasure('render');
Debugbar::addMeasure('now', LARAVEL_START, microtime(true));
Debugbar::measure('My long operation', function() {
// Do something…
});
Or log exceptions:
try {
throw new Exception('foobar');
} catch (Exception $e) {
Debugbar::addException($e);
}
There are also helper functions available for the most common calls:
// All arguments will be dumped as a debug message
debug($var1, $someString, $intValue, $object); start_measure('render','Time for rendering');
stop_measure('render');
add_measure('now', LARAVEL_START, microtime(true));
measure('My long operation', function() {
// Do something…
});
If you want you can add your own DataCollectors, through the Container or the Facade:
Debugbar::addCollector(new DebugBar\DataCollector\MessagesCollector('my_messages'));
//Or via the App container:
$debugbar = App::make('debugbar');
$debugbar->addCollector(new DebugBar\DataCollector\MessagesCollector('my_messages'));
By default, the Debugbar is injected just before </body>
. If you want to inject the Debugbar yourself, set the config option 'inject' to false and use the renderer yourself and follow http://phpdebugbar.com/docs/rendering.html
$renderer = Debugbar::getJavascriptRenderer();
Note: Not using the auto-inject, will disable the Request information, because that is added After the response. You can add the default_request datacollector in the config as alternative.
Enabling/Disabling on run time
You can enable or disable the debugbar during run time.
\Debugbar::enable();
\Debugbar::disable();
NB. Once enabled, the collectors are added (and could produce extra overhead), so if you want to use the debugbar in production, disable in the config and only enable when needed.
Twig Integration
Laravel Debugbar comes with two Twig Extensions. These are tested with rcrowe/TwigBridge 0.6.x
Add the following extensions to your TwigBridge config/extensions.php (or register the extensions manually)
'Barryvdh\Debugbar\Twig\Extension\Debug',
'Barryvdh\Debugbar\Twig\Extension\Dump',
'Barryvdh\Debugbar\Twig\Extension\Stopwatch',
The Dump extension will replace the dump function to output variables using the DataFormatter. The Debug extension adds adebug()
function which passes variables to the Message Collector, instead of showing it directly in the template. It dumps the arguments, or when empty; all context variables.
{{ debug() }}
{{ debug(user, categories) }}
The Stopwatch extension adds a stopwatch tag similar to the one in Symfony/Silex Twigbridge.
{% stopwatch "foo" %}
…some things that gets timed
{% endstopwatch %}
Laravel Debugbar的更多相关文章
- Laravel 调试利器 —— Laravel Debugbar 扩展包安装及使用教程
1.简介 Laravel Debugbar 在 Laravel 5 中集成了 PHP Debug Bar ,用于显示调试及错误信息以方便开发.该扩展包包含了一个 ServiceProvider 用于注 ...
- Laravel --- 【转】安装调试利器 Laravel Debugbar
[转]http://www.tuicool.com/articles/qYfmmur 1.简介 Laravel Debugbar 在 Laravel 5 中集成了 PHP Debug Bar ,用于显 ...
- 如何使用Laravel Debugbar?
非常好用的Laravel debug工具,一定要安装 Chrome/FireFox 都会自带一些 debug 工具可以帮助我们 debug 前端,如 CSS.JavaScript… 等,但若要 deb ...
- Laravel 调试器 Debugbar 和数据库导出利器 DbExporter 扩展安装及注意事项
一.Debugbar安装 参考:Laravel 调试利器 —— Laravel Debugbar 扩展包安装及使用教程 的“2.安装”部分 二.DbExporter安装 参考:Laravel 扩展推荐 ...
- Laravel 5 性能优化技巧
说明 性能一直是 Laravel 框架为人诟病的一个点,所以调优 Laravel 程序算是一个必学的技能. 接下来分享一些开发的最佳实践,还有调优技巧,大家有别的建议也欢迎留言讨论. 这里是简单的列表 ...
- laravel性能优化
1. 配置信息缓存 使用以下 Artisan 自带命令,把 config 文件夹里所有配置信息合并到一个文件里,减少运行时文件的载入数量: php artisan config:cache 上面命令会 ...
- 10个技巧优化PHP程序Laravel 5框架
10个技巧优化PHP程序Laravel 5框架 性能一直是 Laravel 框架为人诟病的一个点,所以调优 Laravel 程序算是一个必学的技能. 接下来分享一些开发的最佳实践www.itxdl.c ...
- laravel 5 优化
性能一直是 Laravel 框架为人诟病的一个点,所以调优 Laravel 程序算是一个必学的技能. 接下来分享一些开发的最佳实践,还有调优技巧,大家有别的建议也欢迎留言讨论. 这里是简单的列表: 配 ...
- 十个 Laravel 5 程序优化技巧
性能一直是 Laravel 框架为人诟病的一个点,所以调优 Laravel 程序算是一个必学的技能. 接下来分享一些开发的最佳实践,还有调优技巧,大家有别的建议也欢迎留言讨论. 这里是简单的列表: 配 ...
随机推荐
- 【php】基础学习2
主要包括数组的学习,具体如下: <html xmlns=http://www.w3.org/1999/xhtml> <head> <meta http-equiv=Con ...
- OAF_OAF组件系列1 - Item Style汇总(概念)
20150506 Created By BaoXinjian
- PLSQL_Oracle基本概念总结(汇总)
2014-08-16 Created By BaoXinjian
- 关闭VS的实时调试器
今天要安装一个水晶报表.安装过程有几个文件有错误.结果这个vs的实时调试器老是调出来.而且还是5次跳出来等你取消5次之后,才到默认的忽略的界面.你知道有多烦的,还得看这他,点完一次还要等几秒钟.差点崩 ...
- Spring里的aop实现方式和源码分析
使用"横切"技术,AOP把软件系统分为两个部分:核心关注点和横切关注点.业务处理的主要流程是核心关注点,与之关系不大的部分是横切关注点.横切关注点的一个特点是,他们经常发生在核心关 ...
- Spring Cloud构建微服务架构(三)断路器
在分布式架构中,断路器模式的作用也是类似的,当某个服务单元发生故障(类似用电器发生短路)之后,通过断路器的故障监控(类似熔断保险丝),向调用方返回一个错误响应,而不是长时间的等待.这样就不会使得线程因 ...
- Diamond 3.5简易教程(二)------软件的简单使用
二.软件的简单使用 工程建立后我们就可以进行程序的编写添加了. 选择左下角file list 选项卡 这里主要是工程的信息. 在input files 上右键弹出选项addànew file... 在 ...
- 【Android】3.19 示例19--全景图HelloWorld
分类:C#.Android.VS2015.百度地图应用: 创建日期:2016-02-04 百度全景图是一种实景地图服务.为用户提供城市.街道和其他环境的360度全景图像,用户可以通过该服务获得如临其境 ...
- android购物车遇到的问题
近期 做购物车的时候 ,遇到几个问题.如今 总结例如以下: 1:不让listview复用组件(购物车.或者有特殊操作的时候): 自己保存全部的view对象 public View getView(fi ...
- HDU 4565 So Easy!(公式化简+矩阵)
转载:http://www.klogk.com/posts/hdu4565/ 这里写的非常好,看看就知道了啊. 题意很easy.a,b,n都是正整数.求 Sn=⌈(a+b√)n⌉%m,(a−1)2&l ...