Commit c50a4ce6 authored by MBoretto's avatar MBoretto

Introducing Exception logging

parent cb1d270c
......@@ -143,7 +143,7 @@ try {
echo $result->getDescription();
}
} catch (Longman\TelegramBot\Exception\TelegramException $e) {
echo $e->getMessage();
echo $e;
}
......@@ -168,7 +168,7 @@ try {
$telegram->handle();
} catch (Longman\TelegramBot\Exception\TelegramException $e) {
// log telegram errors
// echo $e->getMessage();
// echo $e;
}
```
## getUpdate installation NEW!
......@@ -193,7 +193,7 @@ try {
$telegram->handleGetUpdates();
} catch (Longman\TelegramBot\Exception\TelegramException $e) {
// log telegram errors
echo $e->getMessage();
echo $e;
}
......@@ -291,9 +291,9 @@ You can also log incoming messages on a text file, set this option with the meth
$telegram->setLogRequests(true);
$telegram->setLogPath($BOT_NAME.'.log');
```
-----
Thrown Exception are stored in TelegramException.log file.
-----
This code is available on
[Github](https://github.com/akalongman/php-telegram-bot). Pull
requests are welcome.
......
......@@ -31,5 +31,5 @@ try {
$telegram->handleGetUpdates();
} catch (Longman\TelegramBot\Exception\TelegramException $e) {
// log telegram errors
echo $e->getMessage();
echo $e;
}
......@@ -27,5 +27,5 @@ try {
$telegram->handle();
} catch (Longman\TelegramBot\Exception\TelegramException $e) {
// log telegram errors
// echo $e->getMessage();
// echo $e;
}
......@@ -14,5 +14,5 @@ try {
echo $result->getDescription();
}
} catch (Longman\TelegramBot\Exception\TelegramException $e) {
echo $e->getMessage();
echo $e;
}
......@@ -11,4 +11,14 @@ namespace Longman\TelegramBot\Exception;
class TelegramException extends \Exception
{
public function __construct($message, $code = 0)
{
parent::__construct($message, $code);
$path = 'TelegramException.log';
$status = file_put_contents($path, date('Y-m-d H:i:s', time()) .' '. self::__toString() . "\n", FILE_APPEND);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment