Move PHP logging

This commit is contained in:
Daniil Gentili 2018-12-27 22:39:31 +01:00
parent aea8f0c3e3
commit a85a5e0fd1
2 changed files with 22 additions and 10 deletions

View File

@ -742,10 +742,30 @@ class MTProto implements TLCallback
Exception::$rollbar = false;
RPCErrorException::$rollbar = false;
}
$backtrace = debug_backtrace(0);
if (php_sapi_name() !== 'cli') {
if (isset($this->settings['logger']['logger_param']) && basename($this->settings['logger']['logger_param']) === 'MadelineProto.log') {
$this->settings['logger']['logger_param'] = dirname(end($backtrace)['file']) . "/MadelineProto.log";
}
}
$this->logger = new \danog\MadelineProto\Logger($this->settings['logger']['logger'], isset($this->settings['logger']['logger_param']) ? $this->settings['logger']['logger_param'] : '', isset($this->authorization['user']) ? isset($this->authorization['user']['username']) ? $this->authorization['user']['username'] : $this->authorization['user']['id'] : '', isset($this->settings['logger']['logger_level']) ? $this->settings['logger']['logger_level'] : Logger::VERBOSE, isset($this->settings['logger']['max_size']) ? $this->settings['logger']['max_size'] : 100 * 1024 * 1024);
if (!\danog\MadelineProto\Logger::$default) {
\danog\MadelineProto\Logger::constructor($this->settings['logger']['logger'], $this->settings['logger']['logger_param'], isset($this->authorization['user']) ? isset($this->authorization['user']['username']) ? $this->authorization['user']['username'] : $this->authorization['user']['id'] : '', isset($this->settings['logger']['logger_level']) ? $this->settings['logger']['logger_level'] : Logger::VERBOSE, isset($this->settings['logger']['max_size']) ? $this->settings['logger']['max_size'] : 100 * 1024 * 1024);
}
if (php_sapi_name() !== 'cli') {
try {
error_reporting(E_ALL);
ini_set("log_errors", 1);
ini_set("error_log", dirname(end($backtrace)['file']) . "/MadelineProto.log");
error_log('Enabled PHP logging');
} catch (\danog\MadelineProto\Exception $e) {
$this->logger->logger("Could not enable PHP logging");
}
}
}
public function reset_session($de = true, $auth_key = false)

View File

@ -51,17 +51,9 @@ trait Loop
} catch (\danog\MadelineProto\Exception $e) {
$needs_restart = true;
}
$backtrace = debug_backtrace(0);
try {
error_reporting(E_ALL);
ini_set("log_errors", 1);
ini_set("error_log", dirname(end($backtrace)['file']) . "/MadelineProto.log");
error_log('Enabled PHP logging');
} catch (\danog\MadelineProto\Exception $e) {
$this->logger->logger("Could not enable PHP logging");
}
$this->logger->logger($needs_restart ? 'Will self-restart' : 'Will not self-restart');
$backtrace = debug_backtrace(0);
$lockfile = dirname(end($backtrace)['file']) . '/bot.lock';
unset($backtrace);
$try_locking = true;