jeremykenedy/laravel-exception-notifier
Composer 安装命令:
composer require jeremykenedy/laravel-exception-notifier
包简介
Laravel exception notifier will send an email of of the error along with the stack trace to the chosen recipients.
关键字:
README 文档
README
Table of contents:
About
Laravel exception notifier will send an email of the error along with the stack trace to the chosen recipients. This Package includes all necessary traits, views, configs, and Mailers for email notifications upon your applications exceptions. You can customize who send to, cc to, bcc to, enable/disable, and custom subject or default subject based on environment. Built for Laravel 5.2, 5.3, 5.4, 5.5, 5.6, 5.7, 5.8, 6, 7, 8, 9, and 10.
Get the errors and fix them before the client even reports them, that's why this exists!
Requirements
Installation Instructions
-
From your projects root folder in terminal run:
Laravel 9-10 use:
composer require jeremykenedy/laravel-exception-notifier
Laravel 7-8 use:
composer require jeremykenedy/laravel-exception-notifier:2.2.0
Laravel 6 and below use:
composer require jeremykenedy/laravel-exception-notifier:1.2.0
-
Register the package
-
Laravel 5.5 and up Uses package auto discovery feature, no need to edit the
config/app.phpfile. -
Laravel 5.4 and below Register the package with laravel in
config/app.phpunderproviderswith the following:
jeremykenedy\laravelexceptionnotifier\LaravelExceptionNotifier::class,
- Publish the packages view, mailer, and config files by running the following from your projects root folder:
php artisan vendor:publish --tag=laravelexceptionnotifier
NOTE: If upgrading to Laravel 9 or 10 from an older version of this package you will need to republish the assets with:
php artisan vendor:publish --force --tag=laravelexceptionnotifier
- In
App\Exceptions\Handler.phpinclude the additional following classes in the head:
Laravel 9 and Above use:
use App\Mail\ExceptionOccurred; use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Mail; use Throwable;
Laravel 8 and Below use:
use App\Mail\ExceptionOccured; use Illuminate\Support\Facades\Log; use Mail; use Symfony\Component\Debug\Exception\FlattenException; use Symfony\Component\Debug\ExceptionHandler as SymfonyExceptionHandler;
- Update
App\Exceptions\Handler.php
Laravel 9 and Above:
Add the sendEmail() method:
/** * Sends an email upon exception. */ public function sendEmail(Throwable $exception): void { try { $content = [ 'message' => $exception->getMessage(), 'file' => $exception->getFile(), 'line' => $exception->getLine(), 'trace' => $exception->getTrace(), 'url' => request()->url(), 'body' => request()->all(), 'ip' => request()->ip(), ]; Mail::send(new ExceptionOccurred($content)); } catch (Throwable $exception) { Log::error($exception); } }
Add or update the register() method:
/** * Register the exception handling callbacks for the application. */ public function register(): void { $this->reportable(function (Throwable $e) { $enableEmailExceptions = config('exceptions.emailExceptionEnabled'); if ($enableEmailExceptions) { $this->sendEmail($e); } }); }
Laravel 8 and Below:
Replace the report() method with:
/** * Report or log an exception. * * This is a great spot to send exceptions to Sentry, Bugsnag, etc. * * @param \Throwable $exception * * @return void */ public function report(Throwable $exception) { $enableEmailExceptions = config('exceptions.emailExceptionEnabled'); if ($enableEmailExceptions === '') { $enableEmailExceptions = config('exceptions.emailExceptionEnabledDefault'); } if ($enableEmailExceptions && $this->shouldReport($exception)) { $this->sendEmail($exception); } parent::report($exception); }
Add the method sendEmail():
/** * Sends an email upon exception. * * @param \Throwable $exception * * @return void */ public function sendEmail(Throwable $exception) { try { $e = FlattenException::create($exception); $handler = new SymfonyExceptionHandler(); $html = $handler->getHtml($e); Mail::send(new ExceptionOccured($html)); } catch (Throwable $exception) { Log::error($exception); } }
-
Configure your email settings in the
.envfile. -
Add the following (optional) settings to your
.envfile and enter your settings:- Note: the defaults for these are located in
config/exception.php
- Note: the defaults for these are located in
EMAIL_EXCEPTION_ENABLED=false
EMAIL_EXCEPTION_FROM="${MAIL_FROM_ADDRESS}"
EMAIL_EXCEPTION_TO='email1@gmail.com, email2@gmail.com'
EMAIL_EXCEPTION_CC=''
EMAIL_EXCEPTION_BCC=''
EMAIL_EXCEPTION_SUBJECT=''
Screenshots
File Tree
└── laravel-exception-notifier
├── .gitignore
├── LICENSE
├── composer.json
├── readme.md
└── src
├── .env.example
├── App
│ ├── Mail
│ │ └── ExceptionOccurred.php
│ └── Traits
│ └── ExceptionNotificationHandlerTrait.php
├── LaravelExceptionNotifier.php
├── config
│ └── exceptions.php
└── resources
└── views
└── emails
└── exception.blade.php
- Tree command can be installed using brew:
brew install tree - File tree generated using command
tree -a -I '.git|node_modules|vendor|storage|tests'
License
Laravel-Exception-Notifier | A Laravel Exceptions Email Notification Package is open-sourced software licensed under the MIT license
jeremykenedy/laravel-exception-notifier 适用场景与选型建议
jeremykenedy/laravel-exception-notifier 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 277.67k 次下载、GitHub Stars 达 138, 最近一次更新时间为 2017 年 05 月 19 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「email」 「exception」 「notification」 「laravel」 「Laravel-Exceptions」 「exception-handler」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 jeremykenedy/laravel-exception-notifier 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 jeremykenedy/laravel-exception-notifier 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 jeremykenedy/laravel-exception-notifier 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
This package makes it easy to send notifications via AfricasTalking with Laravel
Apple Push Notification & Feedback Provider
Throttle notifications on a per-channel basis
Extensible library for building notifications and sending them via different delivery channels.
Email+ extends Kirby's email capabilities by adding support for multiple email services using the same Kirby email API.
Error and Exception override and observers.
统计信息
- 总下载量: 277.67k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 139
- 点击次数: 35
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-05-19