Skip to content

Commit c50a4ce

Browse files
committed
Introducing Exception logging
1 parent cb1d270 commit c50a4ce

File tree

5 files changed

+18
-8
lines changed

5 files changed

+18
-8
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ try {
143143
echo $result->getDescription();
144144
}
145145
} catch (Longman\TelegramBot\Exception\TelegramException $e) {
146-
echo $e->getMessage();
146+
echo $e;
147147
}
148148

149149

@@ -168,7 +168,7 @@ try {
168168
$telegram->handle();
169169
} catch (Longman\TelegramBot\Exception\TelegramException $e) {
170170
// log telegram errors
171-
// echo $e->getMessage();
171+
// echo $e;
172172
}
173173
```
174174
## getUpdate installation NEW!
@@ -193,7 +193,7 @@ try {
193193
$telegram->handleGetUpdates();
194194
} catch (Longman\TelegramBot\Exception\TelegramException $e) {
195195
// log telegram errors
196-
echo $e->getMessage();
196+
echo $e;
197197
}
198198

199199

@@ -291,9 +291,9 @@ You can also log incoming messages on a text file, set this option with the meth
291291
$telegram->setLogRequests(true);
292292
$telegram->setLogPath($BOT_NAME.'.log');
293293
```
294-
-----
295-
294+
Thrown Exception are stored in TelegramException.log file.
296295

296+
-----
297297
This code is available on
298298
[Github](https://github.com/akalongman/php-telegram-bot). Pull
299299
requests are welcome.

example-getUpdatesCLI.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,5 @@
3131
$telegram->handleGetUpdates();
3232
} catch (Longman\TelegramBot\Exception\TelegramException $e) {
3333
// log telegram errors
34-
echo $e->getMessage();
34+
echo $e;
3535
}

example-hook.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,5 @@
2727
$telegram->handle();
2828
} catch (Longman\TelegramBot\Exception\TelegramException $e) {
2929
// log telegram errors
30-
// echo $e->getMessage();
30+
// echo $e;
3131
}

example-set.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@
1414
echo $result->getDescription();
1515
}
1616
} catch (Longman\TelegramBot\Exception\TelegramException $e) {
17-
echo $e->getMessage();
17+
echo $e;
1818
}

src/Exception/TelegramException.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,14 @@
1111

1212
class TelegramException extends \Exception
1313
{
14+
15+
public function __construct($message, $code = 0)
16+
{
17+
parent::__construct($message, $code);
18+
19+
$path = 'TelegramException.log';
20+
$status = file_put_contents($path, date('Y-m-d H:i:s', time()) .' '. self::__toString() . "\n", FILE_APPEND);
21+
22+
}
23+
1424
}

0 commit comments

Comments
 (0)