alhumsi/laravel-error-notifier 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

alhumsi/laravel-error-notifier

Composer 安装命令:

composer require alhumsi/laravel-error-notifier

包简介

Laravel package for actionable error notifications and auto actions

README 文档

README

Latest Version Total Downloads PHP Version License

Laravel package for actionable error notifications (Telegram, Slack, Discord) with contextual analysis and actionable suggestions.

Highlights

  • Auto-wires into Laravel’s exception handler once the service provider boots.
  • Ships with Analyzer, MessageFormatter and Notifier abstractions for easy extension.
  • Supports Slack, Telegram and Discord out of the box (drop-in HTTP hooks).
  • Maps exception types to severity levels and channels, so high-signal alerts stay actionable.
  • Ships with MarkdownV2-safe formatting plus JSON context blocks for deeper debugging.

Screenshots

Slack Telegram Discord
Slack Error Telegram Error Discord Error

Requirements

  • PHP 8.2+
  • Laravel 10.x, 11.x or 12.x (or any app relying on Illuminate components)
  • Enabled HTTP client (Illuminate\Support\Facades\Http)
  • Optional: queue workers if you decide to dispatch notifications asynchronously

Installation

composer require alhumsi/laravel-error-notifier
php artisan vendor:publish --tag=error-notifier-config

Add the following to your .env (only the services you plan to use are required):

ERROR_NOTIFIER_SLACK_WEBHOOK=https://hooks.slack.com/services/xxx/yyy/zzz
ERROR_NOTIFIER_TELEGRAM_BOT_TOKEN=123456:ABC
ERROR_NOTIFIER_TELEGRAM_CHAT_ID=123456789
ERROR_NOTIFIER_DISCORD_WEBHOOK=https://discord.com/api/webhooks/xxx/yyy
ERROR_NOTIFIER_THROTTLE_ENABLED=true
ERROR_NOTIFIER_MAINTENANCE_ENABLED=false

The package auto-discovers its service provider. No manual edits to config/app.php are necessary.

Quickstart

  1. Install and publish the config (see above).
  2. Adjust config/error-notifier.php levels and channels:
    'levels' => [
        'emergency' => ['slack', 'telegram'],
        'critical' => ['slack'],
        'error' => ['discord'],
    ];
  3. Map custom exceptions to levels under the analyzers array.
  4. Trigger any exception in your app; you should see a formatted alert on the configured channel(s).

The package hooks into Laravel’s reportable callback:

$this->app->make(\Illuminate\Contracts\Debug\ExceptionHandler::class)
    ->reportable(fn (Throwable $e) => app(ExceptionListener::class)->handle($e));

Configuration Essentials

  • channels: provide the transport credentials. Telegram needs bot_token, chat_id and optional bot_url.
  • levels: severity => channels mapping. Empty arrays silence that severity.
  • analyzers: class => severity override, allowing priority routing for specific exceptions.
  • icons: severity => emoji mapping. Customize the visual indicator for each error level.

Custom Icons

Define emojis or strings for each severity level in config/error-notifier.php:

'icons' => [
    'emergency' => '🚨',
    'critical' => '🔥',
    'error' => '',
    // ...
],

Custom Analyzer

Implement alhumsi\ErrorNotifier\Contracts\AnalyzerInterface and bind it inside a service provider:

use alhumsi\ErrorNotifier\Contracts\AnalyzerInterface;
use App\Support\CustomAnalyzer;

public function register()
{
    $this->app->singleton(AnalyzerInterface::class, CustomAnalyzer::class);
}

Custom Formatter

Provide your own MessageFormatterInterface implementation if you need per-channel formatting tweaks (attachments, embeds, etc.).

Custom Notifier / Async Delivery

Swap NotifierInterface with a queue-backed implementation to push payloads to jobs or any other transport you prefer.

Examples

See the additional guides under docs/:

  • docs/getting-started.md: full walkthrough with publishing, environments and troubleshooting.
  • docs/examples.md: channel routing, per-project overrides, manual invocation snippets.

Local Testing

composer test

Includes an integration test (tests/ErrorFlowTest.php) that mocks the notifier and asserts both Slack and Telegram deliveries.

Package Structure

laravel-error-notifier/
├── config/             # Configuration file
├── docs/               # Additional documentation
├── src/                # Source code
│   ├── Console/
│   │   └── FeatureLockCommand.php
│   ├── Contracts/
│   │   ├── AnalyzerInterface.php
│   │   ├── MessageFormatterInterface.php
│   │   └── NotifierInterface.php
│   ├── Http/
│   │   └── Middleware/
│   │       └── CheckFeatureLock.php
│   ├── Listeners/
│   │   ├── ExceptionListener.php
│   │   └── LogListener.php
│   ├── Services/
│   │   ├── FeatureLocker.php
│   │   └── Maintainer.php
│   ├── Analyzer.php    # Exception analyzer
│   ├── MessageFormatter.php # Notification formatter
│   ├── Notifier.php    # Notification sender
│   └── Throttler.php   # Rate limiting logic
├── tests/              # Automated tests
└── vendor/             # Composer dependencies

Contributing

  1. Fork & clone
  2. Run composer install
  3. Add or adjust tests
  4. Open a PR with a summary of changes

License

MIT © Abdullah ALhumsi

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

alhumsi/laravel-error-notifier 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2 次下载、GitHub Stars 达 1, 最近一次更新时间为 2025 年 11 月 24 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 2
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 20
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-11-24