Commit ada1aee8 authored by MBoretto's avatar MBoretto

Implementring suggestions

parent 5bdfccf4
## Logging
Telegram bot library feats monolog to store logs.
Telegram bot library feats [Monolog](https://github.com/Seldaek/monolog) to store logs.
Logs are divided in those streams:
### Error
Collects all the exceptions throwned by the library:
```php
$telegram->setErrorLog($path . '/' . $BOT_NAME . '_error.log');
TelegramLog::initErrorLog($path . '/' . $BOT_NAME . '_error.log');
```
### Debug
Stores Curl messages with the server, useful for debugging:
```php
$telegram->setDebugLog($path . '/' . $BOT_NAME . '_debug.log');
TelegramLog::initDebugLog($path . '/' . $BOT_NAME . '_debug.log');
```
### Raw data
Incoming updates (json string from webhook and getUpdates) can be logged in a text file. Set this option with the methods:
```php
$telegram->setUpdateLog($path . '/' . $BOT_NAME . '_update.log');
TelegramLog::initUpdateLog($path . '/' . $BOT_NAME . '_update.log');
```
Why I need raw log?
Telegram api changes continuously and often happen that db schema is not uptodate with new entities/features. So can happen that your table schema would not be able to store valuable new information coming from Telegram.
......@@ -31,9 +31,7 @@ Remember always backup first!!
Error and Debug streams relies on the `bot_log` instance that can be provided from an external source:
```php
$telegram->enableExternalLog($insert_ here_your_extenl_monolog_instance)
TelegramLog::initialize($monolog);
```
Raw data relies on the `bot_update_log` instance that feats a custom format for this kind of logs.
......@@ -42,11 +42,10 @@ try {
//$telegram->setCommandConfig('date', ['google_api_key' => 'your_google_api_key_here']);
//// Logging
//$telegram->enableExternalLog($insert_ here_your_extenl_monolog_instance)
//$path = 'your_path'
//$telegram->setErrorLog($path . '/' . $BOT_NAME . '_error.log');
//$telegram->setDebugLog($path . '/' . $BOT_NAME . '_debug.log');
//$telegram->setUpdateLog($path . '/' . $BOT_NAME . '_update.log');
//\Longman\TelegramBot\TelegramLog::initialize($your_external_monolog_instance);
//\Longman\TelegramBot\TelegramLog::initErrorLog($path . '/' . $BOT_NAME . '_error.log');
//\Longman\TelegramBot\TelegramLog::initDebugLog($path . '/' . $BOT_NAME . '_debug.log');
//\Longman\TelegramBot\TelegramLog::initUpdateLog($path . '/' . $BOT_NAME . '_update.log');
//// Set custom Upload and Download path
//$telegram->setDownloadPath('../Download');
......
......@@ -40,11 +40,10 @@ try {
//$telegram->setCommandConfig('date', ['google_api_key' => 'your_google_api_key_here']);
//// Logging
//$telegram->enableExternalLog($insert_ here_your_extenl_monolog_instance)
//$path = 'your_path'
//$telegram->setErrorLog($path . '/' . $BOT_NAME . '_error.log');
//$telegram->setDebugLog($path . '/' . $BOT_NAME . '_debug.log');
//$telegram->setUpdateLog($path . '/' . $BOT_NAME . '_update.log');
//\Longman\TelegramBot\TelegramLog::initialize($your_external_monolog_instance);
//\Longman\TelegramBot\TelegramLog::initErrorLog($path . '/' . $BOT_NAME . '_error.log');
//\Longman\TelegramBot\TelegramLog::initDebugLog($path . '/' . $BOT_NAME . '_debug.log');
//\Longman\TelegramBot\TelegramLog::initUpdateLog($path . '/' . $BOT_NAME . '_update.log');
//// Set custom Upload and Download path
//$telegram->setDownloadPath('../Download');
......
......@@ -67,20 +67,6 @@ class Telegram
*/
protected $update;
/**
* Log verbose curl output
*
* @var bool
*/
protected $log_requests;
/**
* Log path
*
* @var string
*/
protected $log_path;
/**
* Upload path
*
......@@ -95,13 +81,6 @@ class Telegram
*/
protected $download_path;
/**
* Log verbosity
*
* @var int
*/
protected $log_verbosity = 1;
/**
* MySQL integration
*
......@@ -232,6 +211,7 @@ class Telegram
require_once $file->getPathname();
$command_obj = $this->getCommandObject($command);
if ($command_obj instanceof Commands\Command) {
$commands[$command_name] = $command_obj;
......@@ -268,60 +248,6 @@ class Telegram
return null;
}
/**
* Redirect log stream to an existing monolog entity
*
* @param \Monolog\Logger $monolog
* @param string $table_prefix
*/
public function enableExternalLog(\Monolog\Logger $monolog = null)
{
TelegramLog::initialize($monolog);
}
/**
* Set error log
*
* @param string $path
*
* @return Telegram
*/
public function setErrorLog($path)
{
TelegramLog::initErrorLog($path);
return $this;
}
/**
* Set requests log
*
* For debug purpore logs all requests done from Request.php
*
* @param string $path
*
* @return Telegram
*/
public function setDebugLog($path)
{
TelegramLog::initDebugLog($path);
return $this;
}
/**
* Set Update log
*
* Log row request coming from Telegram
*
* @param string $path
*
* @return Telegram
*/
public function setUpdateLog($path)
{
TelegramLog::initUpdateLog($path);
return $this;
}
/**
* Set custom input string for debug purposes
*
......
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