A powerful Discord-based Monolog driver for Laravel that sends rich, detailed log messages to Discord channels via webhooks.
- PHP: ^7.2.5 | ^8.0
- Laravel: ^7.0 | ^8.0 | ^9.0 | ^10.0 | ^11.0 | ^12.0
- GuzzleHttp: ^7.0
- Discord: Webhook URL with appropriate permissions
- Easy Installation: One-command setup with auto-configuration
- Multiple Log Levels: Complete support for all Monolog levels with color coding
- Environment Control: Smart environment-based logging activation
- Rich Context: Comprehensive information collection and formatting
- Professional UI: Beautiful Discord embeds with emojis and color coding
- Built-in Commands: Status check, testing, and installation commands
- Web Interface: Interactive testing panel with real-time results
- API Routes: RESTful endpoints for programmatic testing
- Exception Handling: Detailed exception information with stack traces
- Request Tracking: Complete HTTP request information capture
- User Context: Automatic user identification and tracking
- Memory Monitoring: System resource usage tracking
- Smart Formatting: Automatic JSON formatting for complex data
- Robust Error Handling: Silent failure mode prevents app crashes
- Performance Optimized: Field limits and efficient data processing
- Security Features: Sensitive data filtering and path sanitization
- Configurable Limits: Customizable field and message length limits
composer require renslabs/laravel-logger-discord-channel
Run the install command to automatically configure the package:
php artisan logger:discord-install
This will:
- Add Discord channel configuration to
config/logging.php
- Add environment variables to
.env
- Show next steps for setup
If you prefer manual setup, add this to your config/logging.php
channels array:
'discord' => [
'driver' => 'custom',
'via' => \renslabs\LoggerDiscordChannel\DiscordLogger::class,
'level' => env('DISCORD_LOG_LEVEL', 'debug'),
'webhook' => env('DISCORD_WEBHOOK_URL'),
'message' => env('DISCORD_MESSAGE', null),
'context' => env('DISCORD_INCLUDE_CONTEXT', false),
'suffix' => env('DISCORD_LOG_SUFFIX', config('app.name')),
'environment' => ['production', 'staging', 'local'],
'max_field_length' => env('DISCORD_MAX_FIELD_LENGTH', 1024),
'max_description_length' => env('DISCORD_MAX_DESCRIPTION_LENGTH', 4000),
],
Add these environment variables to your .env
file:
# Basic Configuration
DISCORD_WEBHOOK_URL=https://discord.com/api/webhooks/YOUR_WEBHOOK_URL
DISCORD_LOG_LEVEL=info
DISCORD_INCLUDE_CONTEXT=true
DISCORD_MAX_FIELD_LENGTH=1024
DISCORD_MAX_DESCRIPTION_LENGTH=4000
For Laravel 11 and above, simply update your .env
file:
# Enable stack logging with multiple channels
LOG_CHANNEL=stack
LOG_STACK=single,discord
# Discord Configuration
DISCORD_WEBHOOK_URL=https://discord.com/api/webhooks/YOUR_WEBHOOK_URL
DISCORD_LOG_LEVEL=info
DISCORD_INCLUDE_CONTEXT=true
DISCORD_MAX_FIELD_LENGTH=1024
DISCORD_MAX_DESCRIPTION_LENGTH=4000
For Laravel 10 and below, you need to update both your config/logging.php
and .env
files:
1. Update config/logging.php
:
'channels' => [
'stack' => [
'driver' => 'stack',
'channels' => ['single', 'discord'],
'ignore_exceptions' => false,
],
// ... other channels
'discord' => [
'driver' => 'custom',
'via' => \renslabs\LoggerDiscordChannel\DiscordLogger::class,
'level' => env('DISCORD_LOG_LEVEL', 'debug'),
'webhook' => env('DISCORD_WEBHOOK_URL'),
'message' => env('DISCORD_MESSAGE', null),
'context' => env('DISCORD_INCLUDE_CONTEXT', false),
'suffix' => env('DISCORD_LOG_SUFFIX', config('app.name')),
'environment' => ['production', 'staging', 'local'],
'max_field_length' => env('DISCORD_MAX_FIELD_LENGTH', 1024),
'max_description_length' => env('DISCORD_MAX_DESCRIPTION_LENGTH', 4000),
],
],
2. Update your .env
file:
# Use stack logging
LOG_CHANNEL=stack
# Discord Configuration
DISCORD_WEBHOOK_URL=https://discord.com/api/webhooks/YOUR_WEBHOOK_URL
DISCORD_LOG_LEVEL=info
DISCORD_INCLUDE_CONTEXT=true
DISCORD_MAX_FIELD_LENGTH=1024
DISCORD_MAX_DESCRIPTION_LENGTH=4000
use Illuminate\Support\Facades\Log;
// Simple error logging
Log::error('Payment processing failed', [
'userId' => auth()->id(),
'amount' => 99.99,
'payment_method' => 'credit_card'
]);
// Info with rich context
Log::info('User registered successfully', [
'userId' => $user->id,
'email' => $user->email,
'source' => 'web_registration',
'metadata' => [
'referrer' => request()->header('referer'),
'ip' => request()->ip()
]
]);
// Exception with full context
try {
$this->processPayment($request);
} catch (Exception $e) {
Log::critical('Payment system failure', [
'exception' => $e,
'userId' => auth()->id(),
'request_data' => $request->except(['password', 'card_number']),
'system_load' => sys_getloadavg()[0]
]);
}
php artisan logger:discord-install # Auto-configure package
php artisan logger:discord-install --force # Overwrite existing config
php artisan logger:discord-status # Comprehensive status check
Checks:
- β Package installation and class loading
- βοΈ Configuration validation
- π Webhook connectivity testing
- π Environment settings verification
- πΎ Memory and system information
php artisan logger:discord-test # Test with default level (info)
php artisan logger:discord-test --level=error # Test error level
php artisan logger:discord-test --level=warning # Test warning level
php artisan logger:discord-test --level=info # Test info level
Option | Description | Default | Example |
---|---|---|---|
level |
Minimum log level to send | debug |
error , warning , info |
webhook |
Discord webhook URL | Required | https://discord.com/api/webhooks/... |
message |
Custom message prefix | null |
"π¨ Alert from MyApp" |
context |
Include full context/stacktrace | false |
true , false |
suffix |
Suffix for log title | App name | "Production Server" |
environment |
Environments where logging is active | ['production', 'staging', 'local'] |
['production'] |
Option | Description | Default | Purpose |
---|---|---|---|
max_field_length |
Maximum Discord field value length | 1024 |
Prevent API errors |
max_description_length |
Maximum embed description length | 4000 |
Discord API limit |
Level | Priority | Emoji | Color | Use Case |
---|---|---|---|---|
emergency |
600 | π¨ | Dark Red | System unusable |
alert |
550 | π΄ | Red | Immediate action required |
critical |
500 | π₯ | Orange Red | Critical conditions |
error |
400 | β | Red | Runtime errors |
warning |
300 | Orange | Exceptional occurrences | |
notice |
250 | π | Blue | Normal but significant |
info |
200 | βΉοΈ | Green | Interesting events |
debug |
100 | π | Gray | Detailed debug info |
Important: Only logs at or above the configured level will be sent to Discord.
- Professional Title: Emoji + Log Level + App Name
- Color-Coded: Different colors for each log level
- Structured Fields: Organized information display
- Timestamp: ISO 8601 format with timezone
- Footer: App branding with Laravel logo
- Environment (local/staging/production)
- Memory usage (formatted)
- Log channel name
- Timestamp with timezone
- Full URL with parameters
- HTTP method (GET, POST, etc.)
- Client IP address
- User agent string
- Referer header
- Custom user ID from context
- Authenticated user (ID + email)
- Session information
- Exception class name
- File path and line number (sanitized)
- Exception code
- Previous exception chain
- Stack trace (if context enabled)
- All context data with smart formatting
- JSON formatting for complex objects
- Automatic field organization
- Length limits for Discord compatibility
When context
is enabled, a separate embed shows:
- Complete context data
- Extra Monolog fields
- JSON formatted for readability
- Proper syntax highlighting
DISCORD_LOG_LEVEL=error
DISCORD_INCLUDE_CONTEXT=false
DISCORD_MAX_FIELD_LENGTH=512
DISCORD_LOG_LEVEL=warning
DISCORD_INCLUDE_CONTEXT=true
DISCORD_MAX_FIELD_LENGTH=1024
DISCORD_LOG_LEVEL=debug
DISCORD_INCLUDE_CONTEXT=true
DISCORD_MAX_FIELD_LENGTH=1024
- β Path Sanitization: Base path stripped from file paths
- β Length Limits: Prevent Discord API overflow
- β Silent Failure: Won't crash your application
- β Timeout Protection: 10-second HTTP timeout
- β Sensitive Data: Easy to exclude sensitive fields
- β Field Limits: Maximum 25 fields per embed
- β Efficient Processing: Optimized data extraction
- β Memory Tracking: Built-in memory usage monitoring
- β Non-blocking: Asynchronous HTTP requests
- β Smart Formatting: Automatic data type handling
Discord webhooks have rate limits:
- 5 requests per 2 seconds per webhook
- 30 requests per minute per webhook
For high-traffic applications, consider:
- Using higher log levels in production
- Implementing custom rate limiting
- Using multiple webhooks for different log levels
# Regenerate autoload files
composer dump-autoload
# Discover packages
php artisan package:discover
# Clear configuration cache
php artisan config:clear
# Check package status
php artisan logger:discord-status
# Test configuration
php artisan logger:discord-test --level=error
- β Verify webhook URL format and validity
- β Check Discord server permissions
- β
Test connectivity:
php artisan logger:discord-status
- β Verify webhook hasn't been deleted or regenerated
- β Check environment configuration matches current env
- β Verify log level settings (debug < info < warning < error)
- β
Run comprehensive diagnosis:
php artisan logger:discord-status
- β Check Discord channel for rate limiting messages
- β
Reduce log level in production (use
error
instead ofdebug
) - β Disable context in high-traffic environments
- β Implement application-level rate limiting
- β Monitor memory usage with built-in tracking
Here's what your logs will look like in Discord:
MIT License. See LICENSE.md for details.
Made with β€οΈ for the Laravel community