|
5 | 5 |  |
6 | 6 | [](https://packagist.org/packages/uzhlaravel/telegramlogs) |
7 | 7 |
|
8 | | -Get real-time Laravel application logs directly in your Telegram channel. This package provides instant monitoring of your application's critical events through Telegram messages, with support for threaded discussions and Markdown formatting. |
| 8 | +Monitor your Laravel application logs in real-time through Telegram. This package delivers instant notifications of critical events directly to your Telegram channel, with support for threaded discussions and Markdown formatting. |
9 | 9 |
|
| 10 | +## Key Features |
10 | 11 |
|
11 | | -## Features |
| 12 | +- **Real-time log delivery** to Telegram channels |
| 13 | +- **One-command installation** with guided setup |
| 14 | +- **Configuration testing** before deployment |
| 15 | +- **Configurable log levels** (emergency to debug) |
| 16 | +- **Threaded discussions** support via Telegram topics |
| 17 | +- **MarkdownV2** formatted messages |
| 18 | +- **JSON** formatted messages |
| 19 | +- **Automatic message splitting** for long logs |
| 20 | +- **Customizable timeout** for API calls |
| 21 | +- **Test command** to verify your setup |
12 | 22 |
|
13 | | -- 📨 Instant delivery of logs to Telegram |
14 | | -- 🔔 Configurable log levels (emergency to debug) |
15 | | -- 🧵 Support for Telegram topic threads |
16 | | -- ✏️ MarkdownV2 formatted messages |
17 | | -- 📦 Automatic splitting of long messages |
18 | | -- ⏱ Configurable timeout for API calls |
19 | | -- 🛠 Test command to verify your setup |
| 23 | +## Prerequisites |
| 24 | + |
| 25 | +Before installation, you'll need: |
| 26 | +1. A Telegram bot token (create one via [BotFather](https://core.telegram.org/bots#botfather)) |
| 27 | +2. A Telegram channel/group chat ID |
| 28 | +3. Laravel 8.0+ application |
20 | 29 |
|
21 | 30 | ## Installation |
22 | 31 |
|
23 | | -You can install the package via composer: |
| 32 | +Install the package via Composer: |
24 | 33 |
|
25 | 34 | ```bash |
26 | 35 | composer require uzhlaravel/telegramlogs |
27 | 36 | ``` |
28 | 37 |
|
29 | | -You can publish the config file with: |
| 38 | +Run the installation command for guided setup: |
| 39 | + |
| 40 | +### One-command Installation |
| 41 | + |
| 42 | +```bash |
| 43 | +php artisan telegramlogs:install |
| 44 | +``` |
| 45 | + |
| 46 | +This will: |
| 47 | +1. Publish the configuration file |
| 48 | +2. Guide you through environment setup |
| 49 | +3. Optionally set Telegram as your default log channel |
| 50 | +4. Test your configuration |
| 51 | + |
| 52 | +### Manual Installation |
| 53 | + |
| 54 | +Publish the configuration file: |
30 | 55 |
|
31 | 56 | ```bash |
32 | 57 | php artisan vendor:publish --tag="telegramlogs-config" |
33 | 58 | ``` |
34 | 59 |
|
35 | | -This is the contents of the published config file: |
36 | 60 |
|
37 | | -```php |
38 | | -return [ |
39 | | - 'bot_token' => env('TELEGRAM_BOT_TOKEN'), |
40 | | - 'chat_id' => env('TELEGRAM_CHAT_ID'), |
41 | | - 'topic_id' => env('TELEGRAM_TOPIC_ID'), |
42 | | -]; |
| 61 | +## Configuration |
| 62 | + |
| 63 | +### Automated Setup |
| 64 | + |
| 65 | +The installation command will guide you through setting up: |
| 66 | + |
| 67 | +```bash |
| 68 | +php artisan telegramlogs:install |
43 | 69 | ``` |
44 | 70 |
|
45 | | -This is the contents in .env: |
| 71 | +### Manual Configuration |
46 | 72 |
|
47 | | -```php |
| 73 | + |
| 74 | +Update your `.env` file with these settings: |
| 75 | + |
| 76 | +```ini |
48 | 77 | TELEGRAM_BOT_TOKEN=your_bot_token_here |
49 | 78 | TELEGRAM_CHAT_ID=your_chat_id_here |
50 | | -# Optional: |
| 79 | +# Optional settings: |
51 | 80 | TELEGRAM_TOPIC_ID=your_thread_id_here |
52 | 81 | TELEGRAM_LOGS_LEVEL=error |
53 | 82 | ``` |
54 | 83 |
|
| 84 | +### Available Log Levels |
| 85 | + |
| 86 | +| Level | Description | |
| 87 | +|------------|--------------------------------------| |
| 88 | +| Debug | Detailed debug information | |
| 89 | +| Info | Informational messages | |
| 90 | +| Notice | Normal but significant events | |
| 91 | +| Warning | Warning conditions | |
| 92 | +| Error | Error conditions | |
| 93 | +| Critical | Critical conditions | |
| 94 | +| Alert | Immediate action required | |
| 95 | +| Emergency | System is unusable | |
| 96 | + |
| 97 | +### Logging Configuration |
| 98 | + |
| 99 | +Set your default log channel in `.env`: |
| 100 | + |
| 101 | +```ini |
| 102 | +LOG_CHANNEL=telegram |
| 103 | +``` |
| 104 | + |
55 | 105 | ## Usage |
56 | 106 |
|
| 107 | +### Basic Logging |
| 108 | + |
57 | 109 | ```php |
58 | | -$telegramlogs = new Uzhlaravel\Telegramlogs(); |
59 | | -echo $telegramlogs->echoPhrase('Hello, Uzhlaravel!'); |
| 110 | +// Basic error logging |
| 111 | +\Log::error('Payment processing failed'); |
| 112 | + |
| 113 | +// Exception handling |
| 114 | +try { |
| 115 | + // Your code |
| 116 | +} catch (\Exception $e) { |
| 117 | + \Log::critical('API Connection Failed: ' . $e->getMessage()); |
| 118 | +} |
| 119 | + |
| 120 | +// Debug messages |
| 121 | +\Log::debug('User authenticated', ['user_id' => auth()->id()]); |
60 | 122 | ``` |
61 | 123 |
|
62 | | -## Testing |
| 124 | +### Command Line Tools |
63 | 125 |
|
| 126 | +#### Test Configuration |
| 127 | + |
| 128 | +```bash |
| 129 | +php artisan telegramlogs:test |
| 130 | +``` |
| 131 | + |
| 132 | +Options: |
| 133 | +- `--message="Custom message"` - Send custom test message |
| 134 | +- `--level=error` - Specify log level |
| 135 | +- `--list` - Show available log levels |
| 136 | +- `--config` - Display current configuration |
| 137 | + |
| 138 | +Example with custom message: |
64 | 139 | ```bash |
65 | | -composer test |
| 140 | +php artisan telegramlogs:test --message="System check" --level=warning |
| 141 | +``` |
| 142 | + |
| 143 | +#### Show Configuration |
| 144 | + |
| 145 | +```bash |
| 146 | +php artisan telegramlogs:test --config |
| 147 | +``` |
| 148 | + |
| 149 | +## Expected Output |
| 150 | + |
| 151 | +Messages in your Telegram channel will appear as formatted JSON: |
| 152 | + |
| 153 | +```json |
| 154 | +{ |
| 155 | + "message": "Database connection failed", |
| 156 | + "level": "CRITICAL", |
| 157 | + "datetime": "2025-08-17T11:55:13.885292+00:00", |
| 158 | + "context": { |
| 159 | + "exception": "PDOException: could not find driver" |
| 160 | + } |
| 161 | +} |
66 | 162 | ``` |
67 | 163 |
|
| 164 | + |
| 165 | + |
| 166 | +## Getting Telegram Credentials |
| 167 | + |
| 168 | +1. **Create a Bot**: Visit [BotFather](https://core.telegram.org/bots#botfather) to create your bot and get the API token |
| 169 | +2. **Get Chat ID**: Add your bot to a channel/group and visit: |
| 170 | + ``` |
| 171 | + https://api.telegram.org/bot<YOUR_BOT_TOKEN>/getUpdates |
| 172 | + ``` |
| 173 | +3. **Enable Topics** (optional): Create a topic in your group to get the topic_id |
| 174 | + |
| 175 | +## Security Considerations |
| 176 | + |
| 177 | +- Keep your bot token secure |
| 178 | +- Restrict bot access to specific chats |
| 179 | +- Review [our security policy](../../security/policy) for vulnerability reporting |
| 180 | + |
68 | 181 | ## Changelog |
69 | 182 |
|
70 | | -Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently. |
| 183 | +See [CHANGELOG](CHANGELOG.md) for version history. |
71 | 184 |
|
72 | 185 | ## Contributing |
73 | 186 |
|
74 | | -Please see [CONTRIBUTING](CONTRIBUTING.md) for details. |
| 187 | +We welcome contributions! Please see [CONTRIBUTING](CONTRIBUTING.md) for guidelines. |
75 | 188 |
|
76 | | -## Security Vulnerabilities |
| 189 | +## License |
77 | 190 |
|
78 | | -Please review [our security policy](../../security/policy) on how to report security vulnerabilities. |
| 191 | +MIT License. See [LICENSE](LICENSE.md) for details. |
79 | 192 |
|
80 | 193 | ## Credits |
81 | 194 |
|
82 | | -- [uzziahlukeka](https://github.com/uzhlaravel) |
| 195 | +- [Uzziahlukeka](https://github.com/Uzziahlukeka/telegrammonitor) |
83 | 196 | - [All Contributors](../../contributors) |
84 | | - |
85 | | -## License |
86 | | - |
87 | | -The MIT License (MIT). Please see [License File](LICENSE.md) for more information. |
|
0 commit comments