laravel 5 debugbar

作者: zigo | 来源:发表于2017-09-30 13:32 被阅读0次

介绍

  • 显示debug信息在浏览器中
  • 运行L5应用的时候会启动一些收集器,其中一些是专门为L5定义的
  • 可配置显示Redirects和(jQery)Ajax Requests

安装

composer require barryvdh/laravel-debugbar
  • laravel 5.x

    通常的方法

    1. 在config/app.php的providers数组中添加:

      Barryvdh\Debugbar\ServiceProvider::class,
      
    2. 在config/app.php的alias数组中添加:

      'Debugbar' => Barryvdh\Debugbar\Facade::class,
      
    3. 复制包的配置文件到本地配置目录中:

      php artisan vendor:publish --provider="Barryvdh\Debugbar\ServiceProvider"
      

    另外一种方法

    app\Providers\AppServiceProvider.php文件中的register方法中:

        if ($this->app->environment() !== 'production') {
            // 注册debugbar
            $this->app->register('Barryvdh\Debugbar\ServiceProvider');
            // 添加别名
            $this->app->alias(Facade::class, 'Debugbar');
        }
    
  • lumen

    1. bootstrap/app.php中添加:
    if (env('APP_DEBUG')) {
        // 加载配置文件
        $app->configure('debugbar');
        // 注册debugbar
        $app->register(Barryvdh\Debugbar\LumenServiceProvider::class);
        $app->alias(Barryvdh\Debugbar\Facade::class, 'Debugbar');
    
    }
    

使用

使用Facade方式添加调试信息,
  • PSR-3的规范(debug, info, notice, warning, error, critical, alert, emergency):
Debugbar::info($object);
Debugbar::error('Error!');
Debugbar::warning('Watch out…');
Debugbar::addMessage('Another message', 'mylabel');
  • 开始,停止计时
Debugbar::startMeasure('render','Time for rendering');
Debugbar::stopMeasure('render');
Debugbar::addMeasure('now', LARAVEL_START, microtime(true));
Debugbar::measure('My long operation', function() {
    // Do something…
});
  • 记录异常
try {
    throw new Exception('foobar');
} catch (Exception $e) {
    Debugbar::addThrowable($e);
}
使用helper function
// 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…
});
添加自己的数据收集器,通过Container或者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'));
在运行中启动或者禁止debugbar
\Debugbar::enable();
\Debugbar::disable();

debugbar开启会产生额外的开销,所以可以在配置中禁止debugbar,然后在需要debugbar的时候,在程序中使用上面对的方法开启debugbar。

相关文章

网友评论

    本文标题:laravel 5 debugbar

    本文链接:https://www.haomeiwen.com/subject/tbigextx.html