tylercd100/monolog-mailgun
Mailgun handler for Monolog in PHP/Laravel apps. Send log records by email through Mailgun with simple configuration, useful for alerts and production error notifications. Lightweight package that plugs into existing Monolog logging stacks.
Log::channel(), Log::error()).config/logging.php for channel definitions, enabling easy A/B testing (e.g., staging vs. production channels).guzzlehttp/guzzle (for Mailgun API calls) and monolog/monolog (already bundled with Laravel)..env-based Mailgun API key/secrets (though not explicitly documented).| Risk Area | Severity | Mitigation Strategy |
|---|---|---|
| Deprecated Package | High | Fork/maintain or replace with spatie/laravel-mailgun-driver (if available). |
| API Key Exposure | Medium | Enforce Laravel’s .env for secrets; avoid hardcoding. |
| Mailgun Rate Limits | Medium | Implement exponential backoff in handler or use Mailgun’s webhooks. |
| No Laravel 10+ Support | High | Test compatibility or patch dependencies (e.g., illuminate/log). |
| No Structured Logging | Low | Extend handler to format logs as JSON for Mailgun’s parsing. |
shouldQueue().)mail driver or a dedicated logging service (e.g., Sentry, Datadog)?Log facade and config/logging.php.Log::channel('mailgun')->useQueue() for async processing.messages:send).single, stack, syslog).App\Exceptions\Handler).composer require tylercd100/monolog-mailgun
config/logging.php:
'channels' => [
'mailgun' => [
'driver' => 'mailgun',
'api_key' => env('MAILGUN_API_KEY'),
'domain' => env('MAILGUN_DOMAIN'),
'from' => 'logs@yourdomain.com',
'to' => 'team@example.com',
'level' => env('MAILGUN_LOG_LEVEL', 'error'),
'formatted' => true, // Optional: JSON formatting
],
],
Log::channel('mailgun')->error()).mail driver or slack handlers with mailgun.AppServiceProvider to bind the channel:
Log::build([
'mailgun' => \Tylercd100\MonologMailgun\MailgunHandler::class,
]);
vendor/illuminate/log/LogManager.php if createMonolog() changes.mailgun channel definitions.error and critical levels only.debug/info for non-production (with level filtering).App\Exceptions\Handler for automatic exception emails.guzzlehttp/guzzle and monolog/monolog..env and use Laravel’s env() helper.formatted, ignore_empty).MailgunHandlerInterface for easier mocking/testing in CI.stack):
'mailgun' => [
'driver' => 'custom',
'via' => \Tylercd100\MonologMailgun\MailgunHandler::class,
'fallback' => 'single', // Fallback to file if Mailgun fails
],
MailgunBatchHandler to group logs (e.g., 1 email/hour for info level).stack with daily rotation).| Failure Scenario | Impact | Mitigation |
|---|---|---|
| Mailgun API Unavailable | Lost logs | Fallback to file/Slack channel. |
| API Key Revoked | No emails sent | Monitor Log::error() failures. |
| Rate Limit Exceeded | Dropped logs | Implement exponential backoff. |
| Mailgun Domain Misconfig | Emails rejected | Validate domain in staging first. |
| Laravel Queue Stalled | Delayed emails | Use database queue with retries. |
Log::channel('mailgun')->... syntax and level thresholds.How can I help you explore Laravel packages today?