javelinorg/exception-notification

异常通知包在 Laravel 应用程序中发生异常时发送邮件通知。

该包的官方仓库似乎已消失,因此该包已被冻结。

1.0.4 2020-12-01 09:48 UTC

This package is auto-updated.

Last update: 2024-06-29 04:52:53 UTC


README

异常通知包在 Laravel 应用程序中发生异常时发送邮件通知。

Latest Version on Packagist Tests Psalm Total Downloads

安装

您可以通过 composer 安装此包

composer require javelinorg/exception-notification

您可以使用以下命令发布配置文件

php artisan vendor:publish --provider="Javelin\ExceptionNotification\ExceptionNotificationServiceProvider" --tag="config"

您可以使用以下命令发布视图文件

php artisan vendor:publish --provider="Javelin\ExceptionNotification\ExceptionNotificationServiceProvider" --tag="views"

这是已发布配置文件的内容

return [

    /*
    |--------------------------------------------------------------------------
    | Exception Notification
    |--------------------------------------------------------------------------
    |
    | Exception notification enabled by default.
    | You can disable by setting enabled to false.
    */

    'enabled' => env('EXCEPTION_NOTIFICATION', true),

    /*
    |--------------------------------------------------------------------------
    | Error email recipients
    |--------------------------------------------------------------------------
    |
    | Here you can specify the list of recipients
    |
    */

    'from' => [
        'address' => env('MAIL_FROM_ADDRESS', 'foo@example.com'),
        'name'    => env('MAIL_FROM_NAME', 'Foo'),
    ],

    /*
    |--------------------------------------------------------------------------
    | Error email recipients
    |--------------------------------------------------------------------------
    |
    | Here you can specify an array of recipients
    |
    */

    'toAddresses' => [
        'email1@example.com',
        'email2@example.com',
        'email3@example.com',
    ],

    /*
    |--------------------------------------------------------------------------
    | Queue customization
    |--------------------------------------------------------------------------
    |
    | Exception notificaiton will send directly by default,
    | Howerver you can enable the use of queues and customize it as per your needs.
    |
    */

    'queueOptions' => [
        'enabled' => env('EXCEPTION_NOTIFICATION_SHOULD_QUEUE',false),
        'queue' => env('EXCEPTION_NOTIFICATION_QUEUE_NAME', 'default'),
        'connection' => env('QUEUE_DRIVER', 'redis'),
    ],

    /*
    |--------------------------------------------------------------------------
    | A list of the exception types that should be reported.
    |--------------------------------------------------------------------------
    |
    | For which exception class emails should be sent?
    |
    | You can use '*' in the array which will in turn reports every
    | exception.
    |
    */

    'report' => [
      '*',
    ],

    /*
    |--------------------------------------------------------------------------
    | Crawler Bots
    |--------------------------------------------------------------------------
    |
    | Ignore Crawler Bots
    | You can use '*" in the array to ignore all kind of bots or you can specify only particular bots.
    |
    */

    'ignored_bots' => [
       '*',
    ],
];

使用方法

如果您的 Laravel 版本为 8.x 或更高

将以下代码块添加到 App/Exceptions/Handler.php 文件中的 register 方法

  $this->reportable(function (Throwable $th) {
    if (! is_null(app()->getProvider('Javelin\ExceptionNotification\ExceptionNotificationServiceProvider'))) {
        app('exceptionNotification')->reportException($th);
      } // <-- The block you added
  });

如果您的 Laravel 版本为 6.x 到 7.x

将以下代码块添加到 App/Exceptions/Handler.php 文件中的 report 方法

 if (! is_null(app()->getProvider('Javelin\ExceptionNotification\ExceptionNotificationServiceProvider'))) {
    app('exceptionNotification')->reportException($exception);
 }

 // Once added, the mehod should look something like this:
  public function report(Exception $exception) {
    if (! is_null(app()->getProvider('Javelin\ExceptionNotification\ExceptionNotificationServiceProvider'))) {
      app('exceptionNotification')->reportException($exception);
    } // <-- The block you added
    parent::report($exception);
  }

安装并配置好 Exception-Notification 后,您可以通过运行以下命令触发测试异常

php artisan exception:throw

测试

要运行测试,请运行以下命令

composer test

更新日志

请参阅 更新日志 了解最近更改的信息。

贡献

有关详细信息,请参阅 贡献指南

鸣谢

许可证

MIT 许可证(MIT)。有关更多信息,请参阅 许可证文件