ipagdevs/monolog-discord-handler 问题修复 & 功能扩展

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

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

ipagdevs/monolog-discord-handler

最新稳定版本:1.0.4

Composer 安装命令:

composer require ipagdevs/monolog-discord-handler

包简介

README 文档

README

Latest Version on Packagist Total Downloads License PHP Version Build Status

Send Monolog logs directly to a Discord webhook using rich embeds, automatic formatting, and safe value normalization.

Installation

composer require ipagdevs/monolog-discord-handler

Usage (Plain Monolog)

use Monolog\Logger;
use Monolog\Level;
use IpagDevs\Logging\DiscordHandler;

$logger = new Logger('app');

$logger->pushHandler(
    new DiscordHandler(
        webhook_url: 'https://discord.com/api/webhooks/xxx',
        level: Level::Debug
    )
);

$logger->error('System error occurred', [
    'user_id' => 123,
    'exception' => new RuntimeException('Critical failure'),
]);

How it works

The handler automatically:

  • Converts logs into Discord embeds

  • Respects Discord field and message limits

  • Normalizes values:

    • array/object → pretty JSON
    • Throwable → formatted stacktrace block
    • Closure → callable[closure]
    • string callables → callable:method
  • Safely truncates large payloads

  • Prevents application crashes (fail-safe HTTP handling)

Laravel Usage

In config/logging.php:

'channels' => [
    'discord' => [
        'driver' => 'monolog',
        'handler' => IpagDevs\Logging\DiscordHandler::class,
        'with' => [
            'webhook_url' => env('DISCORD_WEBHOOK_URL'),
        ],
        'level' => 'debug',
    ],
],

In .env:

DISCORD_WEBHOOK_URL=https://discord.com/api/webhooks/xxx

Example

Log::error('Payment failed', [
    'order_id' => 999,
    'user' => [
        'id' => 1,
        'name' => 'Lucas',
    ],
    'exception' => new RuntimeException('Gateway timeout'),
]);

This will be sent to Discord as an embed with:

  • log level as title
  • message as description
  • context automatically converted into fields

Safety

This handler is designed to be safe by default:

  • never throws exceptions outside the handler
  • never blocks application execution
  • ignores HTTP failures silently

License

The MIT License (MIT). Please see License File for more information.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-04-13

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固