Skip to content

Commit 3c1cca6

Browse files
authored
Update README.md
1 parent 5c49b7c commit 3c1cca6

File tree

1 file changed

+70
-51
lines changed

1 file changed

+70
-51
lines changed

README.md

Lines changed: 70 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,50 @@
1+
# Monolog Telegram 🚀
12

3+
🔔 **Telegram Handler for Monolog** 📝
24

3-
monolog-telegram
4-
=============
5+
## 🎯 Installation
56

6-
🔔 Telegram Handler for Monolog
7+
Install via Composer:
78

9+
```sh
10+
composer require thecoder/laravel-monolog-telegram
11+
```
812

9-
# Installation
10-
-----------
11-
Install using composer:
13+
## ⚙️ Usage
1214

13-
```bash
14-
composer require thecoder/laravel-monolog-telegram
15-
```
15+
Update your `config/logging.php` file to configure the Telegram logging channel.
1616

17-
# Usage
18-
Open config/logging.php and change the file
17+
### ⏳ Running Logs in a Queue
1918

20-
### Run log in a Queue
19+
If a queue name is set, logs will be processed asynchronously in the specified queue. Otherwise, they will run synchronously.
2120

22-
If a queue name is set, the job will run in the specified queue; otherwise, it will run synchronously.
21+
### 🔧 Configuration Example
2322

24-
```php
23+
Modify your `config/logging.php` file:
2524

25+
```php
2626
use TheCoder\MonologTelegram\Attributes\EmergencyAttribute;
2727
use TheCoder\MonologTelegram\Attributes\CriticalAttribute;
2828
use TheCoder\MonologTelegram\Attributes\ImportantAttribute;
2929
use TheCoder\MonologTelegram\Attributes\DebugAttribute;
3030
use TheCoder\MonologTelegram\Attributes\InformationAttribute;
3131
use TheCoder\MonologTelegram\Attributes\LowPriorityAttribute;
3232

33-
....
33+
return [
34+
'channels' => [
35+
'stack' => [
36+
'driver' => 'stack',
37+
'channels' => ['single', 'telegram'],
38+
],
3439

35-
'channels' => [
36-
'stack' => [
37-
'driver' => 'stack',
38-
'channels' => ['single', 'telegram'],
39-
],
40-
41-
....
42-
4340
'telegram' => [
4441
'driver' => 'monolog',
4542
'level' => 'debug',
46-
4743
'handler' => TheCoder\MonologTelegram\TelegramBotHandler::class,
4844
'handler_with' => [
4945
'token' => env('LOG_TELEGRAM_BOT_TOKEN'),
5046
'chat_id' => env('LOG_TELEGRAM_CHAT_ID'),
51-
'topic_id' => env('LOG_TELEGRAM_TOPIC_ID',null),
47+
'topic_id' => env('LOG_TELEGRAM_TOPIC_ID', null),
5248
'bot_api' => env('LOG_TELEGRAM_BOT_API', 'https://api.telegram.org/bot'),
5349
'proxy' => env('LOG_TELEGRAM_BOT_PROXY', null),
5450
'queue' => env('LOG_TELEGRAM_QUEUE', null),
@@ -61,23 +57,22 @@ use TheCoder\MonologTelegram\Attributes\LowPriorityAttribute;
6157
LowPriorityAttribute::class => env('LOG_TELEGRAM_LOWPRIORITY_ATTRIBUTE_TOPIC_ID', null),
6258
]
6359
],
64-
6560
'formatter' => TheCoder\MonologTelegram\TelegramFormatter::class,
6661
'formatter_with' => [
6762
'tags' => env('LOG_TELEGRAM_TAGS', null),
68-
],
63+
],
6964
],
70-
]
71-
65+
],
66+
];
7267
```
7368

74-
With topics_level you can set PHP Attribute(Annotation) to controller function
69+
### 🏷️ Topic-Based Logging
7570

76-
and change the topic id base on this attributes
71+
You can assign a **PHP Attribute (Annotation)** to controller methods, command handlers, or job handlers, enabling topic-based logging. The package will use the first detected attribute to determine the topic for logging messages.
7772

78-
Note: this package will only process first attribute
73+
#### 💡 Example:
7974

80-
Example:
75+
**📌 Controller Method:**
8176

8277
```php
8378
namespace App\Http\Controllers\NewWeb;
@@ -91,48 +86,72 @@ class HomeController extends Controller
9186
#[EmergencyAttribute]
9287
public function index(Request $request)
9388
{
94-
//
89+
// Your logic here
9590
}
9691
}
9792
```
9893

99-
You can customize token, chat_id and topic_id in run time
94+
**⚡ Command or Job Handler:**
10095

10196
```php
97+
namespace App\Jobs;
98+
99+
use Illuminate\Bus\Queueable;
100+
use Illuminate\Contracts\Queue\ShouldBeQueued;
101+
use Illuminate\Foundation\Bus\Dispatchable;
102+
use TheCoder\MonologTelegram\Attributes\CriticalAttribute;
103+
104+
class ProcessData implements ShouldBeQueued
105+
{
106+
use Dispatchable, Queueable;
102107

108+
#[CriticalAttribute]
109+
public function handle()
110+
{
111+
// Job processing logic
112+
}
113+
}
114+
```
115+
116+
### 🔄 Customizing Log Settings at Runtime
117+
118+
You can dynamically set the bot token, chat ID, and topic ID while logging:
119+
120+
```php
103121
logger('message', [
104-
'token' => 'your bot token',
105-
'chat_id' => 'your chat id',
106-
'topic_id' => 'your topic id'
122+
'token' => 'your_bot_token',
123+
'chat_id' => 'your_chat_id',
124+
'topic_id' => 'your_topic_id'
107125
]);
108-
109126
```
110127

111-
Add the following variables to your .env file.
128+
## 📜 Environment Variables
129+
130+
Ensure the following variables are set in your `.env` file:
112131

113-
```dotenv
132+
```ini
114133
LOG_TELEGRAM_BOT_TOKEN=
115134
LOG_TELEGRAM_CHAT_ID=
116135

117-
# If chat groups are used instead of telegram channels,
118-
# and the ability to set topics on groups is enabled,
119-
# this configuration can be utilized.
136+
# 🏷️ If using chat groups with topic support, define the topic ID
120137
LOG_TELEGRAM_TOPIC_ID=
121138

122-
#LOG_TELEGRAM_BOT_API='https://api.telegram.org/bot'
123-
# add tor proxy for restricted country
124-
#LOG_TELEGRAM_BOT_PROXY='socks5h://localhost:9050'
139+
# 🌍 Optional: Change the API endpoint (default is Telegram's official API)
140+
LOG_TELEGRAM_BOT_API='https://api.telegram.org/bot'
125141

126-
# Topic Level
142+
# 🛡️ Optional: Use a proxy (e.g., Tor for restricted regions)
143+
LOG_TELEGRAM_BOT_PROXY='socks5h://localhost:9050'
144+
145+
# 🔥 Topic Level Configurations
127146
LOG_TELEGRAM_EMERGENCY_ATTRIBUTE_TOPIC_ID=
128147
LOG_TELEGRAM_CRITICAL_ATTRIBUTE_TOPIC_ID=
129148
LOG_TELEGRAM_IMPORTANT_ATTRIBUTE_TOPIC_ID=
130149
LOG_TELEGRAM_DEBUG_ATTRIBUTE_TOPIC_ID=
131150
LOG_TELEGRAM_INFORMATION_ATTRIBUTE_TOPIC_ID=
132151
LOG_TELEGRAM_LOWPRIORITY_ATTRIBUTE_TOPIC_ID=
133-
134152
```
135-
# ScreenShot
136153

137-
![image](https://user-images.githubusercontent.com/3877538/172431112-020d7a7c-f515-49bc-961a-3f63c9ff21af.png)
154+
## 📄 License
155+
156+
This package is open-source and available under the MIT License. 🏆
138157

0 commit comments

Comments
 (0)