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.
daily, slack).Queue::failing listener for job failure notifications, integrating seamlessly with the queue system. Ideal for asynchronous workflows where immediate feedback is critical.debug–emergency), enabling fine-grained control over what reaches Telegram (e.g., only error/critical logs)..env variables (TELEGRAM_LOG_BOT_TOKEN, TELEGRAM_LOG_CHAT_ID).config/logging.php to include the telegram channel..env):
TELEGRAM_LOG_LEVEL=error # Production
TELEGRAM_LOG_LEVEL=debug # Local
sendEmail jobs).Log::stack() with a custom processor to split messages.throw: false). Mitigation: Set throw: true in config to log API failures to Laravel’s default channel..env files can be leaked. Mitigation: Use Laravel’s Vault or AWS Secrets Manager for tokens in production.Log::replace()).config:cache Pitfalls: Environment variables aren’t read after caching. Mitigation: Publish the config file (php artisan vendor:publish --tag=telegram-log-channel-config) or use Laravel’s config() helper with fallbacks.sleep() between batches).info logs).LogManager via a custom handler (TelegramHandler). No changes to core logging logic required.stack driver for multi-channel logging:
'stack' => [
'driver' => 'stack',
'channels' => ['daily', 'telegram'], // Telegram as secondary channel
],
Queue::failing, reducing boilerplate for error handling.https://api.telegram.org/bot{token}/sendMessage (no custom endpoints needed).bot_token and chat_id..env:
TELEGRAM_LOG_BOT_TOKEN=123456:ABC-DEF...
TELEGRAM_LOG_CHAT_ID=-1001234567890
TELEGRAM_LOG_LEVEL=error
php artisan telegram-log:test (sends a sample error log).telegram channel to config/logging.php:
'telegram' => [
'driver' => 'telegram',
'token' => env('TELEGRAM_LOG_BOT_TOKEN'),
'chat_id' => env('TELEGRAM_LOG_CHAT_ID'),
'level' => env('TELEGRAM_LOG_LEVEL', 'error'),
'url' => env('TELEGRAM_API_URL', 'https://api.telegram.org'),
'throw' => env('TELEGRAM_THROW', false),
],
.env (Laravel 12+):
LOG_STACK=daily,telegram
Log::error('Test Telegram log', ['context' => 'integration']);
true).debug logs).throw: true + monitoring).Queue::failing compatibility.LineFormatter, FilterProcessor) for log formatting.$processor = new class {
public function __invoke(array $record) {
if (strlen($record['formatted']) > 3000) {
$record['formatted'] = substr($record['formatted'], 0, 3000) . ' [TRUNCATED]';
}
return $record;
}
};
Arhx\TelegramLogChannel\Handlers\TelegramHandler to add retries or rate limiting.FormatterInterface to modify log output.telegram-log:test.How can I help you explore Laravel packages today?