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 程序算是一个必学的技能. 接下来分享一些开发的最佳实践,还有调优技巧,大家有别的建议也欢迎留言讨论. 这里是简单的列表: 配 ...
随机推荐
- 使用Apktools反编译apk应用
使用Apktools反编译apk应用 1.获取APK的classes.dex文件: 得到你想要的应用的apk文件,用解压软件打开apk,从apk中复制出classes.dex文件. 2.classes ...
- Spring 中属性配置
1 注册自定义属性编辑器,方法一.使用BeanFactory, 则用户需要手动调用 registerCustomEditor(Class requiredType, PropertyEditor pr ...
- mysql开启skip-name-resolve 导致root@127.0.0.1(localhost)访问引发的ERROR 1045 (28000)错误解决方案
为什么配置skip-name-resolve? 由于mysql -h${ip} 远程访问速度过慢, mysql -uroot -p123456 根据网友经验(https://www.cnblogs.c ...
- PHP利用MySQL保存session(php5.4之前的处理)
简介 使用MySQL保存session,需要保存三个关键性的数据:session id.session数据.session生命期. 考虑到session的使用方式,没必要使用InnoDB引擎,MyIS ...
- jQuery.ajax() 如何设置 Headers 中的 Accept 内容
其实很简单,首先如果是常见类型,则请直接设置 dataType 属性 $.ajax({ dataType: "json", type: "get", succe ...
- Javascript玩转继承(三)
在前两篇文章中,介绍了构造继承和原型继承.今天把剩下的两种写完,这两种的应用相对于前两种来说应用很少,因此称为是非主流继承方式. 首先,来看非主流继承一:实例继承法.我也不说那么多废话了,既然是非主流 ...
- iOS中使用block传值
转自:http://blog.sina.com.cn/s/blog_60b45f230100yiaf.html 用此方法传值可以替代委托了.具体例子: MainView.h #import <U ...
- 用c写了个后台扫描
/** * Notice: The program is not debug on internet and not use thread supervene. * date : 6-26 * aut ...
- Map Class Example
Here's a quick look at how to use the Scala Map class, with a colllection of Map class examples. The ...
- rpc简介、原理、实例
简介 RPC(Remote Procedure Call,远程过程调用)是建立在Socket之上的,出于一种类比的愿望,在一台机器上运行的主程序,可以调用另一台机器上准备好的子程序,就像LPC(本地过 ...