Skip to content

Commit 3535488

Browse files
committed
Merge pull request php-telegram-bot#200 from MBoretto/monolog
Adventures with Monolog, ready for the real world 👌
2 parents 7ec5489 + 4b3019f commit 3535488

18 files changed

+667
-274
lines changed

README.md

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ A Telegram Bot based on the official [Telegram Bot API](https://core.telegram.or
4343
- [Set Admins](#set-admins)
4444
- [Channel Administration](#channel-administration)
4545
- [Upload and Download directory path](#upload-and-download-directory-path)
46-
- [Logging](#logging)
46+
- [Logging](doc/01-utils.md)
4747
- [Documentation](#documentation)
4848
- [Projects with this library](#projects-with-this-library)
4949
- [Troubleshooting](#troubleshooting)
@@ -511,27 +511,6 @@ $telegram->setDownloadPath('yourpath/Download');
511511
$telegram->setUploadPath('yourpath/Upload');
512512
```
513513

514-
### Logging
515-
Thrown Exceptions are not stored by default. You can Enable this feature adding this line in your 'webhook.php' or 'getUpdates.php'
516-
517-
```php
518-
Longman\TelegramBot\Logger::initialize('your_path/TelegramException.log');
519-
```
520-
521-
Incoming update (json string from webhook and getUpdates) can be logged in a text file. Set those options with the methods:
522-
```php
523-
$telegram->setLogRequests(true);
524-
$telegram->setLogPath($BOT_NAME . '.log');
525-
```
526-
527-
Set verbosity to 3 to also log curl requests and responses from the bot to Telegram:
528-
529-
```php
530-
$telegram->setLogRequests(true);
531-
$telegram->setLogPath($BOT_NAME . '.log');
532-
$telegram->setLogVerbosity(3);
533-
```
534-
535514
## Documentation
536515

537516
Take a look at the repo [Wiki](https://github.com/akalongman/php-telegram-bot/wiki) for further information and tutorials!

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
"require": {
2121
"php": ">=5.5.0",
2222
"ext-pdo": "*",
23-
"ext-curl": "*"
23+
"ext-curl": "*",
24+
"monolog/monolog": "^1.19"
2425
},
2526
"autoload": {
2627
"psr-4": {

composer.lock

Lines changed: 150 additions & 29 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

doc/01-utils.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
## Logging
2+
Telegram bot library feats [Monolog](https://github.com/Seldaek/monolog) to store logs.
3+
4+
Logs are divided in those streams:
5+
### Error
6+
Collects all the exceptions throwned by the library:
7+
8+
```php
9+
TelegramLog::initErrorLog($path . '/' . $BOT_NAME . '_error.log');
10+
```
11+
12+
### Debug
13+
Stores Curl messages with the server, useful for debugging:
14+
15+
```php
16+
TelegramLog::initDebugLog($path . '/' . $BOT_NAME . '_debug.log');
17+
```
18+
19+
### Raw data
20+
Incoming updates (json string from webhook and getUpdates) can be logged in a text file. Set this option with the methods:
21+
```php
22+
TelegramLog::initUpdateLog($path . '/' . $BOT_NAME . '_update.log');
23+
```
24+
Why I need raw log?
25+
Telegram api changes continuously and often happen that db schema is not uptodate with new entities/features. So can happen that your table schema would not be able to store valuable new information coming from Telegram.
26+
27+
If you store raw data you can port all updates on the newest table schema just using [this script](../utils/importFromLog.php).
28+
Remember always backup first!!
29+
30+
## Stream and external sources
31+
Error and Debug streams relies on the `bot_log` instance that can be provided from an external source:
32+
33+
```php
34+
TelegramLog::initialize($monolog);
35+
```
36+
37+
Raw data relies on the `bot_update_log` instance that feats a custom format for this kind of logs.

0 commit comments

Comments
 (0)