scsuoft/laravel-exception-notification

This package is abandoned and no longer maintained. No replacement package was suggested.

Exceptions notification.

2.4.2 2018-01-19 17:33 UTC

This package is not auto-updated.

Last update: 2020-07-10 23:52:07 UTC


README

Software License

This package notifies you when exceptions are thrown on some of your production application.

Installation

composer require scsuoft/laravel-exception-notification

Next, you need to register Service Provider in config/app.php

$providers = [
    ...
    Razorpay\Slack\Laravel\ServiceProviderLaravel5::class,
    
    LaravelExceptionNotification\ExceptionNotificationServiceProvider::class,
    ...
];
$facades = [
    ...
    'Slack' => Razorpay\Slack\Laravel\Facade::class,
    ...
];

and then publish configuration files

php artisan vendor:publish --provider="Razorpay\Slack\Laravel\ServiceProviderLaravel5"

php artisan vendor:publish --provider="LaravelExceptionNotification\ExceptionNotificationServiceProvider"

Configuration

First of all, you have to config config/slack.php

The variable 'endpoint' needs to be defined as your webhook in your slack panel. e.g. 'https://hooks.slack.com/services/xxxxx'

config/exception-notification.php is pretty much self-explanatory, the slack array below will overwrite config/slack.php

Set environment variable EXCEPTION_EMAIL in .env for the your alert email address. Also, you are responsible for email related config in .env

<?php

return [
    /*
     |--------------------------------------------------------------------------
     | Enabled sender drivers
     |--------------------------------------------------------------------------
     |
     | Send a notification about exception in your application to supported channels.
     |
     | Supported: "mail", "slack". You can use multiple drivers.
     |
     */
    'drivers'      => [ 'mail', 'slack' ],

    /*
     |--------------------------------------------------------------------------
     | Enabled application environments
     |--------------------------------------------------------------------------
     |
     | Set environments that should generate notifications.
     |
     */
    'environments' => [ 'production' ],

    /*
     |--------------------------------------------------------------------------
     | Mail Configuration
     |--------------------------------------------------------------------------
     |
     | It uses your app default Mail driver. You shouldn't probably touch the view
     | property unless you know what you're doing.
     |
     */
    'mail'         => [
        'from' => 'sender@example.com',
        'to'   => env('EXCEPTION_EMAIL')
    ],

    /*
     * Uses maknz\slack package.
     */
    'slack'        => [
        'channel'  => '#bugtracker',//needs to be exact channel name
        'username' => 'Exception Notification',//something you just made up
        'icon'     => ':robot_face:',
    ],
];

Usage

To start catching exceptions you have 2 options out there.

First option: Extend from Exception Handler provided by package (app/Exceptions/Handler.php):

use LaravelExceptionNotification\NotificationExceptionHandler;
...
class Handler extends NotificationExceptionHandler

Second option: Make your report method in app/Exceptions/Handler.php to look like this:

public function report(Exception $exception)
{
    foreach ($this->dontReport as $type) {
        if ($exception instanceof $type) {
            return parent::report($exception);
        }
    }

    if (app()->bound('exception-notification')) {
        app('exception-notification')->notifyException($exception);
    }

    return parent::report($exception);
}

License

This library is licensed under the MIT license. Please see License file for more information.