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 程序算是一个必学的技能. 接下来分享一些开发的最佳实践,还有调优技巧,大家有别的建议也欢迎留言讨论. 这里是简单的列表: 配 ...
随机推荐
- 记一次400错误引发的血案(URL中特殊符号的转义/400 bad request错误)
django+nginx+uwsgi部署的站点访问某个URL时发生了400 bad request的错误,而使用django自带的开发版的web server时没有遇到此问题.初步判断是nginx或u ...
- 转 WEB前端性能分析--工具篇
在线网站类: WebPageTest 说明: 在线的站点性能评测网站,地址http://www.webpagetest.org/ 补充: 其实这网站也是个开源项目,所以支持自己搭建一个内部的测试站点 ...
- Android利用广播监听设备网络连接(断网)的变化情况
http://www.open-open.com/lib/view/open1379302453943.html
- Concurrency Managed Workqueue(一)workqueue基本概念
一.前言 workqueue是一个驱动工程师常用的工具,在旧的内核中(指2.6.36之前的内核版本)workqueue代码比较简单(大概800行),在2.6.36内核版本中引入了CMWQ(Concur ...
- Google大牛分享的面试秘籍
我憋了很长时间想写点关于去Google面试的秘籍.不过我总是推迟,因为写出来的东西会让你抓狂.很可能是这样.如果按统计规律来定义“你”的话,这文章很可能让你不爽. 为啥呢?因为啊……好吧,对此我写首小 ...
- ThinkPHP CURD方法中field方法详解
导读:ThinkPHP CURD方法的field方法属于模型的连贯操作方法之一,主要目的是标识要返回或者操作的字段,可以用于查询和写入操作. 1.用于查询在查询操作中field方法是使用最频繁的.$M ...
- Class.getResourceAsStream和ClassLoader.getResourceAsStream方法
项目中,有时候要读取当前classpath下的一些配置文件,下面介绍下Class.getResourceAsStream和ClassLoader.getResourceAsStream两种方法以及两者 ...
- jQuery推断浏览器是移动端还是电脑端自己主动跳转
一个段小代码.同一个站点针对移动端查看和电脑端查看跳转不同的页面. 首先载入jQuery文件. $(function(){ var MobileUA = (function() { var ua = ...
- c#编写远程控制的核心被控端操作类
首先定义一个全局,上线地址,上线端口等 using Control_Client; using Microsoft.Win32; using System; using System.Collecti ...
- C# RSA数据加密
第一步产生密钥类 CreateKey using System; using System.Collections.Generic; using System.Linq; using System.T ...