https://github.com/emotality/laravel-telegram-logger
Laravel package to report exceptions to a Telegram chat, group or channel.
https://github.com/emotality/laravel-telegram-logger
laravel log logger logging telegram telegram-api telegram-bot
Last synced: 12 months ago
JSON representation
Laravel package to report exceptions to a Telegram chat, group or channel.
- Host: GitHub
- URL: https://github.com/emotality/laravel-telegram-logger
- Owner: emotality
- License: mit
- Created: 2023-10-01T22:21:02.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2025-02-24T19:44:26.000Z (over 1 year ago)
- Last Synced: 2025-06-08T02:22:53.801Z (about 1 year ago)
- Topics: laravel, log, logger, logging, telegram, telegram-api, telegram-bot
- Language: PHP
- Homepage:
- Size: 14.6 KB
- Stars: 2
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# Telegram Logger for Laravel
Laravel package to report exceptions to a Telegram chat, group or channel.
## Requirements
- PHP 8.1+
- Laravel 10
## Installation
1. `composer require emotality/laravel-telegram-logger`
2. `php artisan vendor:publish --provider="Emotality\Telegram\TelegramLoggerServiceProvider"`
3. Add the following lines to your `.env`:
```dotenv
TELEGRAM_API_KEY=""
TELEGRAM_CHAT_ID=""
```
4. Add the `telegram` block to the `channels` array, inside your `config/logging.php` file:
```php
'channels' => [
...
'telegram' => [
'driver' => 'telegram',
'level' => 'error',
'cache_ttl' => env('TELEGRAM_CACHE_TTL', 300),
],
],
```
###### _Note: Read more about the `cache_ttl` key below._
5. Update your log stack and add `telegram` to the `channels` array in `config/logging.php`:
```php
'stack' => [
'driver' => 'stack',
'channels' => ['daily', 'telegram'],
...,
],
```
or change your `LOG_CHANNEL` in your `.env`:
```dotenv
LOG_CHANNEL=telegram
```
### Caching TTL explained:
A MD5 checksum is being created for every exception, then that checksum is being cached for the `cache_ttl` seconds you provide. If checksum exists in the cache, the log will not be sent.
In other words, when the exact same exception reoccurs, only the first exception will be logged, if after 300 seconds it still occurs, it will be logged again.
Only the first occurrence of the same exception will be logged every 300 seconds to avoid flooding the Telegram API and your chat.
The `cache_ttl` key accepts `false` to disable caching, meaning, each and every exception will be logged to Telegram, even if it's 1000 of the same exception.
## License
laravel-telegram-logger is released under the MIT license. See [LICENSE](https://github.com/emotality/laravel-telegram-logger/blob/master/LICENSE) for details.