Skip to content

jezzdk/guzzle-debugbar

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Guzzle subscriber to log to debugbar's timeline

Guzzle Subscriber for logging to debugbar's timeline and logs.

Debugbar timeline Debugbar logs

Usage

Just four lines of code are needed to log your requests to debugbar's timeline.

$debugBar = new StandardDebugBar();

// Get data collectors.
$timeline = $debugBar->getCollector('time');
$exceptions = $debugBar->getCollector('exceptions');

// Create the subscriber.
$subscriber = new GuzzleHttp\Subscriber\Log\DebugbarSubscriber($timeline, $exceptions);

// Attach it to the Guzzle client's event emitter.
$client = new GuzzleHttp\Client;
$client->getEmitter()->attach($subscriber);

Now $client is ready to make requests.

Every request is now logged to the timeline, and thrown exceptions are logged to the 'Messages' tab.

Recommended: use Guzzle's LogSubscriber

$debugBar = new StandardDebugBar();

// PSR-3 logger:
$logger = $debugBar->getCollector('messages');

// Create a new LogSubscriber.
$subscriber = new GuzzleHttp\Subscriber\Log\LogSubscriber($logger);

// Attach it to the Guzzle client's event emitter.
$client = new GuzzleHttp\Client;
$client->getEmitter()->attach($subscriber);

Support

Laravel 4+

It is recommended to have my friend Barry's laravel-debugbar configured. Make sure to include the GuzzleHttp\Subscriber\Log\Support\Laravel\ServiceProvider from this package your app's providers array.

If you just want to use a different implementation of DebugBar\DebugBar, create a ServiceProvider that binds an implementation with the key 'debugbar'. For example with this register method:

public function register()
{
    $this->app->singleton('debugbar', function () {
        return new StandardDebugBar;
    });
}

Make sure to create every Guzzle Client via injection or via App::make. Pass on the config array the Guzzle Client's constructor if needed.

public function __construct(\GuzzleHttp\Client $client) {
    $this->client = $client;
    $this->client->get('http://example.org/abolute/url');
}

public function __construct(Illuminate\Foundation\Application $app) {
    $this->client = $app->make('\GuzzleHttp\Client', [['base_url' => 'https://api.github.com']]);
    $this->client->get('/users/hannesvdvreken')->json();
}

'time' is not a registered collector

'exceptions' is not a registered collector

If you see one of these error messages, it means you disabled the time collector and/or the exceptions collector in your packages/barryvdh/laravel-debugbar/config.php. By default these are enabled. This package depends on it, so please enable them both.

Contributing

Please be nice in issues/pull request, and stick to PSR-2. Everything will be just fine. Run tests with composer test.

License

MIT

About

A Guzzle v4+ plugin that lets you log HTTP requests in the PHP debugbar timeline.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 100.0%