arhx/telegram-log-channel
Laravel log channel that sends Monolog messages to a Telegram chat via bot token and chat ID. Configure via .env or logging.php, add to your logging stack, and it safely falls back to a NullHandler when unset. Includes optional queued job failure alerts.
Monolog), acting as a custom channel for Telegram notifications. Complements existing channels (e.g., single, daily, slack) without disrupting core logging workflows.config/logging.php and provide a Telegram bot token/channel ID.guzzlehttp/guzzle (already bundled with Laravel) for HTTP calls to Telegram’s API.ERROR/CRITICAL logs) and message formatting via Monolog processors. Can extend via service providers or custom processors.TELEGRAM_BOT_TOKEN in .env is secure, but misconfiguration (e.g., committing .env) could leak credentials.throw is set to true in config (default: false).telegram-notify job).guzzlehttp/guzzle (already included).extend() method in LogServiceProvider.config/logging.php:
'telegram' => [
'driver' => 'telegram',
'bot_token' => env('TELEGRAM_BOT_TOKEN'),
'chat_id' => env('TELEGRAM_CHAT_ID'),
'level' => env('TELEGRAM_LOG_LEVEL', 'error'),
'url' => env('TELEGRAM_API_URL', 'https://api.telegram.org'),
'throw' => env('TELEGRAM_THROW', false),
],
debug level) to test formatting and volume.throw: false initially to avoid disrupting production.config/logging.php and test locally.TELEGRAM_LOG_LEVEL=error.single file or syslog).StreamHandler, FilterHandler) for log formatting.TelegramHandler class to add retries or rate limiting.bot_token and chat_id.composer require arhx/telegram-log-channel.php artisan vendor:publish --provider="Arhx\TelegramLogChannel\TelegramLogChannelServiceProvider".config/logging.php and .env.Log::error('Test message') in a Tinker session.bot_token/chat_id being misconfigured in environments (use Laravel’s .env validation).AppServiceProvider:
Validator::extend('valid_telegram_token', function ($attribute, $value, $parameters) {
return strlen($value) === 10 && ctype_alnum($value);
});
guzzlehttp/guzzle may require updates. Monitor for breaking changes.$processor = new class {
public function __invoke(array $record) {
if (isset($record['context']['telegram_response'])) {
Log::debug('Telegram API response', $record['context']['telegram_response']);
}
return $record;
}
};
// Custom queue handler
TelegramLogChannel::dispatch($level, $message, $context);
async: true in config (if supported) or queue jobs.| Failure Scenario | Impact | Mitigation | |--------------------------------|-------------------------------------|
How can I help you explore Laravel packages today?