A module for Laravel that allows you to send logs to Telegram.
This module allows you to send logs to a Telegram group, breaking them down by topic. You can describe the configuration for the basic log types or write your own logging levels.
The installation is done using Composer:
composer require prog-time/tg-logger- Create a Telegram bot
- Create a Telegram group and include "Topics" in it
- Specify the variables in .environment
TG_LOGGER_TOKEN="token_bot"
TG_LOGGER_CHAT_ID="id_group"- Add the created bot and grant it administrator rights
- Create a configuration file config/tg-logger.php manually or using a command.
php artisan vendor:publish --tag=config- In config/tg-logger.php specify the bot token, the ID of the created group, and describe the topics that need to be created.
return [
'token' => env('TG_LOGGER_TOKEN'),
'chat_id' => env('TG_LOGGER_CHAT_ID'),
'topics' => [
[
'name' => 'Debug messages',
'icon_color' => '9367192',
'level' => 'debug',
],
[
'name' => 'Cron tasks',
'icon_color' => '9367192',
'level' => 'crone',
],
[
'name' => 'Errors',
'icon_color' => '9367192',
'level' => 'error, notice, warning, emergency',
]
]
];- Run the command to create themes in a group. After executing this command, the file config/tg-logger.php it will be overwritten and the topic IDs for each log type will be indicated in it.
php artisan tglogger:create-topicsTo catch all types of errors, you need to change the basic log handler in the configuration file config/logging.php by specifying the module classes as handlers.
'channels' => [
...
'telegram' => [
'driver' => 'monolog',
'handler' => ProgTime\TgLogger\TgHandler::class,
'formatter' => ProgTime\TgLogger\TgFormatter::class,
'level' => 'debug',
],
...
],
and in .env, change the LOG_CHANNEL parameter
LOG_CHANNEL=telegram
To work with the module directly, you can use the following code.
TgLogger::sendLog('Your message', 'level');