Commit ada1aee8 authored by MBoretto's avatar MBoretto

Implementring suggestions

parent 5bdfccf4
## Logging ## 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: Logs are divided in those streams:
### Error ### Error
Collects all the exceptions throwned by the library: Collects all the exceptions throwned by the library:
```php ```php
$telegram->setErrorLog($path . '/' . $BOT_NAME . '_error.log'); TelegramLog::initErrorLog($path . '/' . $BOT_NAME . '_error.log');
``` ```
### Debug ### Debug
Stores Curl messages with the server, useful for debugging: Stores Curl messages with the server, useful for debugging:
```php ```php
$telegram->setDebugLog($path . '/' . $BOT_NAME . '_debug.log'); TelegramLog::initDebugLog($path . '/' . $BOT_NAME . '_debug.log');
``` ```
### Raw data ### Raw data
Incoming updates (json string from webhook and getUpdates) can be logged in a text file. Set this option with the methods: Incoming updates (json string from webhook and getUpdates) can be logged in a text file. Set this option with the methods:
```php ```php
$telegram->setUpdateLog($path . '/' . $BOT_NAME . '_update.log'); TelegramLog::initUpdateLog($path . '/' . $BOT_NAME . '_update.log');
``` ```
Why I need raw 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. 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!! ...@@ -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: Error and Debug streams relies on the `bot_log` instance that can be provided from an external source:
```php ```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. Raw data relies on the `bot_update_log` instance that feats a custom format for this kind of logs.
...@@ -42,11 +42,10 @@ try { ...@@ -42,11 +42,10 @@ try {
//$telegram->setCommandConfig('date', ['google_api_key' => 'your_google_api_key_here']); //$telegram->setCommandConfig('date', ['google_api_key' => 'your_google_api_key_here']);
//// Logging //// Logging
//$telegram->enableExternalLog($insert_ here_your_extenl_monolog_instance) //\Longman\TelegramBot\TelegramLog::initialize($your_external_monolog_instance);
//$path = 'your_path' //\Longman\TelegramBot\TelegramLog::initErrorLog($path . '/' . $BOT_NAME . '_error.log');
//$telegram->setErrorLog($path . '/' . $BOT_NAME . '_error.log'); //\Longman\TelegramBot\TelegramLog::initDebugLog($path . '/' . $BOT_NAME . '_debug.log');
//$telegram->setDebugLog($path . '/' . $BOT_NAME . '_debug.log'); //\Longman\TelegramBot\TelegramLog::initUpdateLog($path . '/' . $BOT_NAME . '_update.log');
//$telegram->setUpdateLog($path . '/' . $BOT_NAME . '_update.log');
//// Set custom Upload and Download path //// Set custom Upload and Download path
//$telegram->setDownloadPath('../Download'); //$telegram->setDownloadPath('../Download');
......
...@@ -40,11 +40,10 @@ try { ...@@ -40,11 +40,10 @@ try {
//$telegram->setCommandConfig('date', ['google_api_key' => 'your_google_api_key_here']); //$telegram->setCommandConfig('date', ['google_api_key' => 'your_google_api_key_here']);
//// Logging //// Logging
//$telegram->enableExternalLog($insert_ here_your_extenl_monolog_instance) //\Longman\TelegramBot\TelegramLog::initialize($your_external_monolog_instance);
//$path = 'your_path' //\Longman\TelegramBot\TelegramLog::initErrorLog($path . '/' . $BOT_NAME . '_error.log');
//$telegram->setErrorLog($path . '/' . $BOT_NAME . '_error.log'); //\Longman\TelegramBot\TelegramLog::initDebugLog($path . '/' . $BOT_NAME . '_debug.log');
//$telegram->setDebugLog($path . '/' . $BOT_NAME . '_debug.log'); //\Longman\TelegramBot\TelegramLog::initUpdateLog($path . '/' . $BOT_NAME . '_update.log');
//$telegram->setUpdateLog($path . '/' . $BOT_NAME . '_update.log');
//// Set custom Upload and Download path //// Set custom Upload and Download path
//$telegram->setDownloadPath('../Download'); //$telegram->setDownloadPath('../Download');
......
...@@ -67,20 +67,6 @@ class Telegram ...@@ -67,20 +67,6 @@ class Telegram
*/ */
protected $update; protected $update;
/**
* Log verbose curl output
*
* @var bool
*/
protected $log_requests;
/**
* Log path
*
* @var string
*/
protected $log_path;
/** /**
* Upload path * Upload path
* *
...@@ -95,13 +81,6 @@ class Telegram ...@@ -95,13 +81,6 @@ class Telegram
*/ */
protected $download_path; protected $download_path;
/**
* Log verbosity
*
* @var int
*/
protected $log_verbosity = 1;
/** /**
* MySQL integration * MySQL integration
* *
...@@ -232,6 +211,7 @@ class Telegram ...@@ -232,6 +211,7 @@ class Telegram
require_once $file->getPathname(); require_once $file->getPathname();
$command_obj = $this->getCommandObject($command); $command_obj = $this->getCommandObject($command);
if ($command_obj instanceof Commands\Command) { if ($command_obj instanceof Commands\Command) {
$commands[$command_name] = $command_obj; $commands[$command_name] = $command_obj;
...@@ -268,60 +248,6 @@ class Telegram ...@@ -268,60 +248,6 @@ class Telegram
return null; 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 * 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