From dcf0135285f1a515454807cdfe1e819f37a23a86 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Thu, 25 Feb 2021 15:49:30 +0300 Subject: logger: shorter syntax --- classes/logger.php | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) (limited to 'classes/logger.php') diff --git a/classes/logger.php b/classes/logger.php index c917182c1..c227c014c 100755 --- a/classes/logger.php +++ b/classes/logger.php @@ -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(); + } } -- cgit v1.2.3