diff options
author | Andrew Dolgov <[email protected]> | 2021-02-25 15:49:30 +0300 |
---|---|---|
committer | Andrew Dolgov <[email protected]> | 2021-02-25 15:49:30 +0300 |
commit | dcf0135285f1a515454807cdfe1e819f37a23a86 (patch) | |
tree | 923ebbdff110e7890959c38009002307724aec71 /classes/logger.php | |
parent | 59c14e9c0001bc7a01763ecc7d3042dcde978a1a (diff) |
logger: shorter syntax
Diffstat (limited to 'classes/logger.php')
-rwxr-xr-x | classes/logger.php | 24 |
1 files changed, 18 insertions, 6 deletions
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(); + } } |