c0ns0l3/telegram-logger

Send logs to Telegram chat via Telegram bot

1.2.4 2024-03-12 12:04 UTC

This package is auto-updated.

Last update: 2025-04-12 13:12:03 UTC


README

Build Status Total Downloads Latest Stable Version License

  • Send logs to Telegram chat via Telegram bot
  • Support Telegram Topics
  • Compressing exception to HTML file and send it to Telegram for better viewing

Install


composer require c0ns0l3/telegram-logger

Define Telegram Bot Token and chat id (users telegram id) and set as environment parameters. Add to .env

TELEGRAM_LOGGER_BOT_TOKEN=bot_token
TELEGRAM_LOGGER_CHAT_ID=chat_id
TELEGRAM_LOGGER_TOPIC_ID=topic_id #if needed

Add to config/logging.php file new channel:

'telegram' => [
    'driver' => 'custom',
    'via'    => \TelegramLogger\TelegramLogger::class::class,
    'level'  => 'debug',
]

You can also configure any channels with your own options

'debug' => [
    'driver' => 'custom',
    'via'    => \TelegramLogger\TelegramLogger::class::class,
    'level'  => 'debug',
    'chat_id' => 
    'topic_id' => 
    'formatter' => new \Monolog\Formatter\LineFormatter("%message% %context% %extra%\n", null, true, true),
    'options' => [
         'parse_mode' => 'html', #html|text
         'disable_web_page_preview' => true, #true|false
         'disable_notification' => false #true|false
    ]
]

If your default log channel is a stack, you can add it to the stack channel like this

'stack' => [
    'driver' => 'stack',
    'channels' => ['single', 'telegram'],
]

Or you can simply change the default log channel in the .env

LOG_CHANNEL=telegram

Publish config file and views

php artisan vendor:publish --provider "TelegramLogger\TelegramLoggerServiceProvider"