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
2ccc2af1
Commit
2ccc2af1
authored
May 20, 2016
by
MBoretto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
introducing TelegramLog.php
parent
83312bf8
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
135 additions
and
66 deletions
+135
-66
TelegramException.php
src/Exception/TelegramException.php
+0
-13
Logger.php
src/Logger.php
+0
-53
TelegramLog.php
src/TelegramLog.php
+135
-0
No files found.
src/Exception/TelegramException.php
View file @
2ccc2af1
...
...
@@ -10,22 +10,9 @@
namespace
Longman\TelegramBot\Exception
;
use
Longman\TelegramBot\Logger
;
/**
* Main exception class used for exception handling
*/
class
TelegramException
extends
\Exception
{
/**
* Exception constructor that writes the exception message to the logfile
*
* @param string $message Error message
* @param integer $code Error code
*/
public
function
__construct
(
$message
,
$code
=
0
)
{
parent
::
__construct
(
$message
,
$code
);
Logger
::
logException
(
self
::
__toString
());
}
}
src/Logger.php
deleted
100644 → 0
View file @
83312bf8
<?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
;
}
}
src/TelegramLog.php
0 → 100644
View file @
2ccc2af1
<?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.
*/
use
Monolog\Logger
;
use
Monolog\Handler\StreamHandler
;
namespace
Longman\TelegramBot
;
/**
* Class TelegramLog.
*/
class
TelegramLog
{
/**
* Monolog instance
*
* @var \Monolog\Logger
*/
static
protected
$monolog
=
null
;
/**
* Monolog instance for update
*
* @var \Monolog\Logger
*/
static
protected
$monolog_update
=
null
;
/**
* Initialize
*
* Initilize monolog instance. Singleton
* Is possbile provide an external monolog instance
*
* @param \Monolog\Logger
*
* @return \Monolog\Logger
*/
public
static
function
initialize
(
\Monolog\Logger
$external_monolog
=
null
)
{
if
(
self
::
$monolog
===
null
)
{
if
(
$external_monolog
!==
null
)
{
self
::
$monolog
=
$external_monolog
;
}
else
{
self
::
$monolog
=
new
\Monolog\Logger
(
'bot_log'
);
}
}
return
self
::
$monolog
;
}
/**
* Initialize error log
*
* @param string $path
*
* @return \Monolog\Logger
*/
public
static
function
initErrorLog
(
$path
)
{
self
::
initialize
();
return
self
::
$monolog
->
pushHandler
(
new
\Monolog\Handler\StreamHandler
(
$path
,
\Monolog\Logger
::
ERROR
));
}
/**
* Initialize debug log
*
* @param string $path
*
* @return \Monolog\Logger
*/
public
static
function
initDebugLog
(
$path
)
{
self
::
initialize
();
return
self
::
$monolog
->
pushHandler
(
new
\Monolog\Handler\StreamHandler
(
$path
,
\Monolog\Logger
::
DEBUG
));
}
/**
* Initialize update log
*
* Initilize monolog instance. Singleton
* Is possbile provide an external monolog instance
*
* @return \Monolog\Logger
*/
public
static
function
initUpdateLog
()
{
if
(
self
::
$monolog_update
===
null
)
{
self
::
$monolog_update
=
new
\Monolog\Logger
(
'bot_update_log'
);
// Create a formatter
$formatter
=
new
\Monolog\Formatter\LineFormatter
(
'%message%'
);
// Update handler
$update_handler
=
new
\Monolog\Handler\StreamHandler
(
$path
,
\Monolog\Logger
::
INFO
);
$update_handler
->
setFormatter
(
$formatter
);
self
::
$monolog_update
->
pushHandler
(
$update_handler
);
}
return
self
::
$monolog
;
}
/**
* Report error log
*
* @param string $text
*/
public
static
function
error
(
$text
)
{
self
::
$monolog
->
error
(
$text
);
}
/**
* Report debug log
*
* @param string $text
*/
public
static
function
debug
(
$text
)
{
self
::
$monolog
->
debug
(
$text
);
}
/**
* Report update log
*
* @param string $text
*/
public
static
function
update
(
$text
)
{
self
::
$monolog_update
->
info
(
$text
);
}
}
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