1
0
mirror of https://git.tt-rss.org/git/tt-rss.git synced 2025-12-13 01:25:56 +00:00

logger: shorter syntax

This commit is contained in:
Andrew Dolgov
2021-02-25 15:49:30 +03:00
parent 59c14e9c00
commit dcf0135285
13 changed files with 45 additions and 25 deletions

View File

@@ -3,7 +3,7 @@ class Logger {
private static $instance;
private $adapter;
public static $errornames = array(
const ERROR_NAMES = [
1 => 'E_ERROR',
2 => 'E_WARNING',
4 => 'E_PARSE',
@@ -19,10 +19,14 @@ class Logger {
4096 => 'E_RECOVERABLE_ERROR',
8192 => 'E_DEPRECATED',
16384 => 'E_USER_DEPRECATED',
32767 => 'E_ALL');
32767 => 'E_ALL'];
function log_error($errno, $errstr, $file, $line, $context) {
if ($errno == E_NOTICE) return false;
static function log_error(int $errno, string $errstr, string $file, int $line, $context) {
return self::get_instance()->_log_error($errno, $errstr, $file, $line, $context);
}
private function _log_error($errno, $errstr, $file, $line, $context) {
//if ($errno == E_NOTICE) return false;
if ($this->adapter)
return $this->adapter->log_error($errno, $errstr, $file, $line, $context);
@@ -30,7 +34,11 @@ class Logger {
return false;
}
function log($errno, $errstr, $context = "") {
static function log(int $errno, string $errstr, $context = "") {
return self::get_instance()->_log($errno, $errstr, $context);
}
private function _log($errno, $errstr, $context = "") {
if ($this->adapter)
return $this->adapter->log_error($errno, $errstr, '', 0, $context);
else
@@ -57,11 +65,15 @@ class Logger {
}
}
public static function get() : Logger {
private static function get_instance() : Logger {
if (self::$instance == null)
self::$instance = new self();
return self::$instance;
}
static function get() : Logger {
user_error("Please don't use Logger::get(), call Logger::log(...) instead.", E_USER_DEPRECATED);
return self::get_instance();
}
}