laravel-exception-notify - 支持多种通道的 laravel 异常监控通知

laravel-exception-notify - 支持多种通道的 laravel 异常监控通知(钉钉群机器人、飞书群机器人、Server 酱、企业微信群机器人、息知)。

功能

  • 监控发送 laravel 应用异常
  • 支持多种通道(钉钉群机器人、飞书群机器人、Server 酱、企业微信群机器人、息知)
  • 自定义发送的异常信息数据

源码

安装

$ composer require guanguans/laravel-exception-notify -vvv

配置

发布服务

$ php artisan vendor:publish --provider="Guanguans\\LaravelExceptionNotify\\ExceptionNotifyServiceProvider"

申请通道 token 等信息

配置文件中配置 token 等信息

config/exception-notify.php

使用

app/Exceptions/Handler.php 文件中的 report 方法中添加一行代码即可

public function report(Exception $exception)
{
    // 添加的代码
    $this->shouldReport($exception) and \ExceptionNotifier::report($exception);
    // // 或者
    // $this->shouldReport($exception) and app('exception.notifier')->report($exception);
    // // 或者
    // $this->shouldReport($exception) and \Guanguans\LaravelExceptionNotify\Facades\Notifier::report($exception);

    parent::report($exception);
}

通知结果

本作品采用《CC 协议》,转载必须注明作者和本文链接
No practice, no gain in one's wit. 我的 Gitub
《L02 从零构建论坛系统》
以构建论坛项目 LaraBBS 为线索,展开对 Laravel 框架的全面学习。应用程序架构思路贴近 Laravel 框架的设计哲学。
《G01 Go 实战入门》
从零开始带你一步步开发一个 Go 博客项目,让你在最短的时间内学会使用 Go 进行编码。项目结构很大程度上参考了 Laravel。
讨论数量: 9
Jianne

前排支持 :+1:

2年前 评论

@Jianne 谢谢老哥支持,也可以试着用下 :smiley:

2年前 评论

正式环境会报:
PHP Fatal error: Uncaught Error: Class ‘ExceptionNotifier’ not found in
我的代码如下:

 public function report(Throwable $e)
    {
        // 默认通道企业微信通知
        if (false === config('app.debug')) {
            \ExceptionNotifier::reportIf($this->shouldReport($e), $e);
        }
        parent::report($e);
    }
1年前 评论
codepky (作者) 1年前
guanguans (楼主) 1年前

@guanguans
用上面的代码

\Guanguans\LaravelExceptionNotify\Facades\ExceptionNotifier::reportIf();

报如下错误。
Target class [exception.notify] does not exist.
应为我的vendor加入了git版本库。同事的电脑也报这个错误。只有同事电脑执行composer update就没有问题。
直接用notify包的代码是没有问题的

1年前 评论
guanguans (楼主) 1年前

@guanguans 是的需要执行一下composer dump-autoload,可以解决这个问题

1年前 评论

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!
未填写
文章
56
粉丝
126
喜欢
971
收藏
1333
排名:46
访问:15.3 万
私信
所有博文
社区赞助商