Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
TelegramBot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kulya
TelegramBot
Commits
b1184d86
Commit
b1184d86
authored
Feb 27, 2016
by
MBoretto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix Exception Log
parent
f548fa02
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
60 additions
and
8 deletions
+60
-8
README.md
README.md
+4
-1
TelegramException.php
src/Exception/TelegramException.php
+3
-7
Logger.php
src/Logger.php
+53
-0
No files found.
README.md
View file @
b1184d86
...
@@ -427,8 +427,11 @@ $telegram->setUploadPath('yourpath/Upload');
...
@@ -427,8 +427,11 @@ $telegram->setUploadPath('yourpath/Upload');
```
```
### Logging
### Logging
Thrown Exceptions are not stored by default. You can Enable this feature adding this line in your 'webhook.php' or 'getUpdates.php'
Thrown Exceptions are stored in
*TelegramException.log*
file (in the base directory).
```
php
Longman\TelegramBot\Logger
::
initialize
(
'your_path/TelegramException.log'
);
```
Incoming update (json string from webhook and getUpdates) can be logged in a text file. Set those options with the methods:
Incoming update (json string from webhook and getUpdates) can be logged in a text file. Set those options with the methods:
```
php
```
php
...
...
src/Exception/TelegramException.php
View file @
b1184d86
...
@@ -10,6 +10,8 @@
...
@@ -10,6 +10,8 @@
namespace
Longman\TelegramBot\Exception
;
namespace
Longman\TelegramBot\Exception
;
use
Longman\TelegramBot\Logger
;
/**
/**
* Main exception class used for exception handling
* Main exception class used for exception handling
*/
*/
...
@@ -24,12 +26,6 @@ class TelegramException extends \Exception
...
@@ -24,12 +26,6 @@ class TelegramException extends \Exception
public
function
__construct
(
$message
,
$code
=
0
)
public
function
__construct
(
$message
,
$code
=
0
)
{
{
parent
::
__construct
(
$message
,
$code
);
parent
::
__construct
(
$message
,
$code
);
Logger
::
logException
(
self
::
__toString
());
$path
=
'TelegramException.log'
;
$status
=
file_put_contents
(
$path
,
date
(
'Y-m-d H:i:s'
,
time
())
.
' '
.
self
::
__toString
()
.
"
\n
"
,
FILE_APPEND
);
}
}
}
}
src/Logger.php
0 → 100644
View file @
b1184d86
<?php
/**
* This file is part of the TelegramBot package.
*
* (c) Avtandil Kikabidze aka LONGMAN <akalongman@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace
Longman\TelegramBot
;
/**
* Class Logger.
*/
class
Logger
{
/**
* Exception log path
*
* @var string
*/
static
protected
$exception_log_path
=
null
;
/**
* Initialize
*
* @param string $exception_log_path
*/
public
static
function
initialize
(
$exception_log_path
)
{
self
::
$exception_log_path
=
$exception_log_path
;
}
/**
* Log exception
*
* @param string $text
*
* @return bool
*/
public
static
function
logException
(
$text
)
{
if
(
!
is_null
(
self
::
$exception_log_path
))
{
return
file_put_contents
(
self
::
$exception_log_path
,
date
(
'Y-m-d H:i:s'
,
time
())
.
' '
.
$text
.
"
\n
"
,
FILE_APPEND
);
}
return
0
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment