定制 jgodstime/laravel-error-notifier 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

jgodstime/laravel-error-notifier

Composer 安装命令:

composer require jgodstime/laravel-error-notifier

包简介

Error notification for laravel

README 文档

README

This package sends you email and slack notification whenever 500 internal server errors happens in your application. This package only works for laravel 8, 9 and 10 This package works for both API and view based laravel project

alt text

What the package sends as a notification

  • Last route the user visited
  • If they are authenticated or not
  • User ID (If user is authenticated)
  • User email (If user is authenticated)
  • User error description message (After form is submitted, for a non view based App)
  • File Error (The actual file the error was associated with)
  • Line Number (The line number the error happened)
  • Trace error (The list of files associated with the error; before and after form is submitted)

How to install

composer require jgodstime/laravel-error-notifier

In your /app/Exceptions/Handler.php file, in the register method, add \ErrorNotifier\Notify\Helper::getError($e); this must be inside reportable callback

    public function register()
    {
    	$this->reportable(function (Throwable  $e)  {
    		 \ErrorNotifier\Notify\Helper::getError($e);
    	});
    }

Disable Instant Notification

By default this package sends notification immediately the error occured i.e without waiting for users description of the error, you can disable this by adding NOTIFIER_INSTANT=false in your .env file

Publishing the vendor files

By default, Laravel displays the 500 error page in your /views/errors/500.blade.php file when a 500 error occurs in your application

This package places the 500.blade.php file in the /views/errors/ folder after you publish the vendor file

If you already have a 500.blade.php file in your /views/errors folder and you want to use this package; you should remove or move it to another folder.

Publish the vendor files if your app is not API

php artisan vendor:publish --provider="ErrorNotifier\Notify\ErrorNotifierServiceProvider"

Now the vendor files are published in their respective paths

Let's Test

Setup your email driver

To setup your email driver, you can use mailtrap for test purpose.

    MAIL_DRIVER=smtp
    MAIL_HOST=sandbox.smtp.mailtrap.io
    MAIL_PORT=587
    MAIL_USERNAME=528a733...
    MAIL_PASSWORD=73c29...
    MAIL_ENCRYPTION=tls
    MAIL_FROM_ADDRESS=mygoogle@gmail.com
    MAIL_FROM_NAME="${APP_NAME}"

Disable notification to email

To disable notification to email, set NOTIFIER_EMAIL= in your .env file

Add your slack webhook (Optional)

To setup your slack webhook url

LOG_SLACK_WEBHOOK_URL=https://hooks.slack.com/services/T....

We are good 😊

To test this, simply add $array['key1'] = 'john'; $data = $array['key2']; in one of your routes, then hit the route In your browser.

    Route::get('/convert/file', function(){
    	 $array['key1'] = 'john';
        $data  = $array['key2'];
    });

Notice that we are trying to access an array with key2 that doesn’t exist, this will throw an error and the package will send the error as notification to your email as well as the trace.

Also, you must turn APP_DEBUG=false and LOG_LEVEL=debug in your .env file

You should see this

alt text

If you don’t have NOTIFIER_INSTANT=false in your .env file, the package sends instant notification to the setup email and slack channel

Also, after user submits the form, the package sends another notification with user error description message.

Modify Page Design

You can modify the style for the page to suit your taste,

Note: Be careful not to change the form route and hidden inputs.

A notification email is sent to the email specified in the laravel environment variable (MAIL_FROM_ADDRESS) in your .env file

You can change this by adding NOTIFIER_EMAIL="hello@example.com" in your .env file.

Send Email to Multiple Recipients

You can send notification to multiple recipients by adding multiple emails as a string in comma separated format without space

NOTIFIER_EMAIL="hello1@example.com,hello2@example.com"

Change Redirect Page URL

You can change the page user is taken to after submitting the form, by default it goes to the home page (/)

NOTIFIER_REDIRECT_URL='/thank-you'

Exciting upgrade coming. Stay tuned!

How can I thank you?

Why not star the github repo? I'd love the attention! Why not share the link for this repository on Twitter, LinkedIn or HackerNews? Spread the word!

Don't forget to follow me on twitter!

Thanks! Godstime John.

jgodstime/laravel-error-notifier 适用场景与选型建议

jgodstime/laravel-error-notifier 是一款 基于 Blade 开发的 Composer 扩展包,目前已累计 1.57k 次下载、GitHub Stars 达 43, 最近一次更新时间为 2022 年 07 月 01 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 jgodstime/laravel-error-notifier 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 jgodstime/laravel-error-notifier 我们能提供哪些服务?
定制开发 / 二次开发

基于 jgodstime/laravel-error-notifier 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 1.57k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 44
  • 点击次数: 8
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 43
  • Watchers: 1
  • Forks: 3
  • 开发语言: Blade

其他信息

  • 授权协议: Unknown
  • 更新时间: 2022-07-01