File tree 3 files changed +60
-8
lines changed
3 files changed +60
-8
lines changed Original file line number Diff line number Diff line change @@ -427,8 +427,11 @@ $telegram->setUploadPath('yourpath/Upload');
427
427
```
428
428
429
429
### Logging
430
+ Thrown Exceptions are not stored by default. You can Enable this feature adding this line in your 'webhook.php' or 'getUpdates.php'
430
431
431
- Thrown Exceptions are stored in * TelegramException.log* file (in the base directory).
432
+ ``` php
433
+ Longman\TelegramBot\Logger::initialize('your_path/TelegramException.log');
434
+ ```
432
435
433
436
Incoming update (json string from webhook and getUpdates) can be logged in a text file. Set those options with the methods:
434
437
``` php
Original file line number Diff line number Diff line change 10
10
11
11
namespace Longman \TelegramBot \Exception ;
12
12
13
+ use Longman \TelegramBot \Logger ;
14
+
13
15
/**
14
16
* Main exception class used for exception handling
15
17
*/
@@ -24,12 +26,6 @@ class TelegramException extends \Exception
24
26
public function __construct ($ message , $ code = 0 )
25
27
{
26
28
parent ::__construct ($ message , $ code );
27
-
28
- $ path = 'TelegramException.log ' ;
29
- $ status = file_put_contents (
30
- $ path ,
31
- date ('Y-m-d H:i:s ' , time ()) . ' ' . self ::__toString () . "\n" ,
32
- FILE_APPEND
33
- );
29
+ Logger::logException (self ::__toString ());
34
30
}
35
31
}
Original file line number Diff line number Diff line change
1
+ <?php
2
+ /**
3
+ * This file is part of the TelegramBot package.
4
+ *
5
+ * (c) Avtandil Kikabidze aka LONGMAN <[email protected] >
6
+ *
7
+ * For the full copyright and license information, please view the LICENSE
8
+ * file that was distributed with this source code.
9
+ */
10
+
11
+ namespace Longman \TelegramBot ;
12
+
13
+ /**
14
+ * Class Logger.
15
+ */
16
+ class Logger
17
+ {
18
+ /**
19
+ * Exception log path
20
+ *
21
+ * @var string
22
+ */
23
+ static protected $ exception_log_path = null ;
24
+
25
+ /**
26
+ * Initialize
27
+ *
28
+ * @param string $exception_log_path
29
+ */
30
+ public static function initialize ($ exception_log_path )
31
+ {
32
+ self ::$ exception_log_path = $ exception_log_path ;
33
+ }
34
+
35
+ /**
36
+ * Log exception
37
+ *
38
+ * @param string $text
39
+ *
40
+ * @return bool
41
+ */
42
+ public static function logException ($ text )
43
+ {
44
+ if (!is_null (self ::$ exception_log_path )) {
45
+ return file_put_contents (
46
+ self ::$ exception_log_path ,
47
+ date ('Y-m-d H:i:s ' , time ()) . ' ' . $ text . "\n" ,
48
+ FILE_APPEND
49
+ );
50
+ }
51
+ return 0 ;
52
+ }
53
+ }
You can’t perform that action at this time.
0 commit comments