ipagdevs/monolog-discord-handler

Maintainers

Package info

github.com/ipagdevs/monolog-discord-handler

pkg:composer/ipagdevs/monolog-discord-handler

Statistics

Installs: 4

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

1.0.4 2026-04-16 18:44 UTC

This package is auto-updated.

Last update: 2026-04-16 18:45:32 UTC


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.