Send logs to Telegram chat via Telegram bot in your Laravel application
composer require revangelista/telegram-logger
Set a new channel in the config/logging.php file, with the following variables:
'telegram' => [
'driver' => 'custom',
'via' => Logger\TelegramLogger::class,
'level' => 'debug',
'token' => '<YOUR_BOT_TOKEN>',
'chat_id' => '<CHAT_ID>',
]
Where token is the token of your Telegram bot and chat_id is where the bot will send the messages
If you want your Telegram bot to send log messages for more than one chat at the same time, you can write the channel settings like this:
'telegram' => [
'driver' => 'custom',
'via' => Logger\TelegramLogger::class,
'level' => 'debug',
'token' => '<YOUR_BOT_TOKEN>',
'chat_id' => [
'<CHAT_ID_1>',
'<CHAT_ID_2>',
'<CHAT_ID_3>'
]
]
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
For more information on custom log channels, check the Laravel documentation on this.
For using this package you need to create Telegram bot
- Go to @BotFather in the Telegram
- Send
/newbot
- Set up name and bot-name for your bot.
- Get token and add it to your .env file (it is written above)
- Go to your bot and send
/start
message