LaravelPackages.net
Acme Inc.
Toggle sidebar
zanysoft/laravel-exception-monitor

A lightweight Laravel package that notifies you of exceptions in your application via email, Slack, or Microsoft Teams.

284
1
2.0.3
About zanysoft/laravel-exception-monitor

zanysoft/laravel-exception-monitor is a Laravel package for a lightweight laravel package that notifies you of exceptions in your application via email, slack, or microsoft teams.. It currently has 1 GitHub stars and 284 downloads on Packagist (latest version 2.0.3). Install it with composer require zanysoft/laravel-exception-monitor. Discover more Laravel packages by zanysoft or browse all Laravel packages to compare alternatives.

Last updated

Software License Total Downloads Version Maintained Framwork

Laravel Exception Monitor

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

Installation

composer require zanysoft/laravel-exception-monitor

If you’re on Laravel 5.4 or earlier, you’ll need to add the following to your config/app.php (for Laravel 5.5 and up these will be auto-discovered by Laravel):

'providers' => [
    //...
    ZanySoft\LaravelExceptionMonitor\ExceptionMonitorServiceProvider::class,
],

'aliases' => [
    //...
    'ExceptionMonitor' => ZanySoft\LaravelExceptionMonitor\Facades\ExceptionMonitor::class,
];

Publish the package config and view files to your application. Run these commands inside your terminal.

php artisan vendor:publish --provider="ZanySoft\LaravelExceptionMonitor\ExceptionMonitorServiceProvider"

You need set Incoming Webhooks for sending messages to Slack and MS Teams.

Configuration

Config File is pretty self-explanatory.

<?php

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

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

    /*
     |--------------------------------------------------------------------------
     | Disable Error Notifications
     |--------------------------------------------------------------------------
     |
     | Set status code for disable notifications. like [401,404,500] 
     |
     */
    'skip_error' => [401, 404, 405, 500],

    /*
     |--------------------------------------------------------------------------
     | 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' => '[email protected]',
        'to'   => '[email protected]',
        'view' => 'mails/exception-monitor'
    ],

    /*
     * set endpoint url from Incoming WebHooks https://my.slack.com/services/new/incoming-webhook
     */
    'slack' => [
        'endpoint' => 'https://hooks.slack.com/services/....',
        'channel' => '#bugtracker',
        'username' => 'Exception Monitor',
        'icon' => ':robot_face:',
    ],
    
    /*
     * Set endpoint url from Incoming WebHooks
     */
    'teams' => [
        'endpoint' => env('TEAMS_WEBHOOK_URL'),
        'title' => env('TEAMS_MESSAGE_TITLE', env('app_name')),
        'style' => 'card', // Display error type in teams notification. Allowed value: true (default) and false
        'show_user' => true, // Display authenticated user (if available). Allowed value: false (default) and true
        'exception_limit' => 5, // Display number of exception lines (trace). Set null for hide and -1 for all Default: 10,
        'avatar' => null,
        'color' => 'FF8000', // set message style color
    ],
];

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 ZanySoft\LaravelExceptionMonitor\MonitorExceptionHandler;
...
class Handler extends MonitorExceptionHandler

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

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

    if (app()->bound('exception-monitor')) {
        app('exception-monitor')->notifyException($e);
    }
  
    // OR
  
    ExceptionMonitor::notifyException($e);

    parent::report($e);
}

Examples

Slack
Slack

Teams
Teams

Issues

If you discover any issues, please email me at [email protected] instead of using the issue tracker.

License

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

Comments