博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Laravel Debugbar
阅读量:6286 次
发布时间:2019-06-22

本文共 4266 字,大约阅读时间需要 14 分钟。

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 messagedebug($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 

$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  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  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  similar to the one in Symfony/Silex Twigbridge.

{% stopwatch "foo" %}    …some things that gets timed{% endstopwatch %}

转载地址:http://pyiva.baihongyu.com/

你可能感兴趣的文章
GCC知识
查看>>
实验4 IIC通讯与EEPROM接口
查看>>
几个smarty小技巧
查看>>
Cocos2d-x3.2 Grid3D网格动作
查看>>
Java (for循环综合应用)
查看>>
NodeJs——(10)REST风格的路由规则
查看>>
软件可扩展性:来自星巴克的经验
查看>>
Java Cache系列之Guava Cache实现详解
查看>>
深入Log4J源码之LoggerRepository和Configurator
查看>>
System V 消息队列—复用消息
查看>>
vi常用快捷键
查看>>
Code Jam 2010 Round 1A Problem A
查看>>
C语言柔性数组
查看>>
iOS学习之flappyBird游戏的实现
查看>>
Cocos2D v2.0至v3.x简洁转换指南(五)
查看>>
springMVC4(8)模型数据绑定全面分析
查看>>
设计模式 - 适配器
查看>>
CSS之可折叠导航
查看>>
淘宝美工设计师细说何为天猫透明背景
查看>>
【B/S学习总结】我的第100篇CSDN博客
查看>>