afterbug/afterbug-laravel

AfterBug error monitoring for Laravel applications.

1.0.0 2018-05-10 16:20 UTC

This package is not auto-updated.

Last update: 2024-12-22 07:21:53 UTC


README

StyleCI Total Downloads Latest Stable Version Latest Unstable Version License

This library detects errors and exceptions in your Laravel application and reports them to AfterBug for alerts and reporting.

Features

  • Automatically report exceptions and errors
  • Send customized diagnostic data
  • Attach user information to determine how many people are affected by the error.

Installation

The preferred way to install this extension is through composer.

Either run

composer require afterbug/afterbug-laravel "~1.0"

or Add afterbug/afterbug-laravel to your composer.json

"afterbug/afterbug-laravel": "~1.0"

Usage

If you're on Laravel 5.4 or earlier, you need to register the ServiceProvider in config/app.php

'providers' => [
    // ...
    AfterBug\AfterBugLaravel\AfterBugServiceProvider::class,
],

Publish the default configuration

php artisan vendor:publish --provider='AfterBug\AfterBugLaravel\AfterBugServiceProvider'

Add AfterBug reporting to app/Exceptions/Handler.php:

public function report(Exception $e)
{
    if ($this->shouldReport($e)) {
        AfterBug::catchException($e);
    }

    return parent::report($e);
}

Callbacks

Set a callback to customize the data.

AfterBug::registerCallback(function ($config) {
    $config->setMetaData([
        'custom' => 'Your custom data', 
    ]);
})->catchException($e);

Sentinel

If you are using sentinel instead of laravel Auth, you have to setup user callback manually.

AfterBug::registerCallback(function ($config) {
    if (Sentinel::check()) {
        $config->setUser(
            Sentinel::getUser()->toArray()
        );
    }
})->catchException($e);

Add your AfterBug Api Key to .env:

AFTERBUG_API_KEY=Your_API_Key