ipagdevs / monolog-discord-handler
Package info
github.com/ipagdevs/monolog-discord-handler
pkg:composer/ipagdevs/monolog-discord-handler
1.0.4
2026-04-16 18:44 UTC
Requires
- php: ^8.3
- guzzlehttp/guzzle: ^7.10
- monolog/monolog: ^3.10
Requires (Dev)
- pestphp/pest: ^4.5
- phpstan/phpstan: ^2.1
README
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.