From ee8887d561d57cc3b7b0163435956d06fda63ae2 Mon Sep 17 00:00:00 2001 From: kenjis Date: Sun, 24 Sep 2023 17:46:25 +0900 Subject: [PATCH] fix: incorrect Logger interface --- system/Common.php | 8 +++++--- system/Log/Logger.php | 39 +++++++++++++++++++------------------- system/Test/TestLogger.php | 5 +++-- 3 files changed, 27 insertions(+), 25 deletions(-) diff --git a/system/Common.php b/system/Common.php index ebfd8e2565e8..4ec6cbbbadbf 100644 --- a/system/Common.php +++ b/system/Common.php @@ -794,7 +794,7 @@ function lang(string $line, array $args = [], ?string $locale = null) * - info * - debug * - * @return bool + * @return void */ function log_message(string $level, string $message, array $context = []) { @@ -804,10 +804,12 @@ function log_message(string $level, string $message, array $context = []) if (ENVIRONMENT === 'testing') { $logger = new TestLogger(new Logger()); - return $logger->log($level, $message, $context); + $logger->log($level, $message, $context); + + return; } - return Services::logger(true)->log($level, $message, $context); // @codeCoverageIgnore + Services::logger(true)->log($level, $message, $context); // @codeCoverageIgnore } } diff --git a/system/Log/Logger.php b/system/Log/Logger.php index b1583f5d789c..4d4e36a8afad 100644 --- a/system/Log/Logger.php +++ b/system/Log/Logger.php @@ -15,6 +15,7 @@ use CodeIgniter\Log\Handlers\HandlerInterface; use Psr\Log\LoggerInterface; use RuntimeException; +use Stringable; use Throwable; /** @@ -157,9 +158,9 @@ public function __construct($config, bool $debug = CI_DEBUG) * * @param string $message */ - public function emergency($message, array $context = []): bool + public function emergency(string|Stringable $message, array $context = []): void { - return $this->log('emergency', $message, $context); + $this->log('emergency', $message, $context); } /** @@ -170,9 +171,9 @@ public function emergency($message, array $context = []): bool * * @param string $message */ - public function alert($message, array $context = []): bool + public function alert(string|Stringable $message, array $context = []): void { - return $this->log('alert', $message, $context); + $this->log('alert', $message, $context); } /** @@ -182,9 +183,9 @@ public function alert($message, array $context = []): bool * * @param string $message */ - public function critical($message, array $context = []): bool + public function critical(string|Stringable $message, array $context = []): void { - return $this->log('critical', $message, $context); + $this->log('critical', $message, $context); } /** @@ -193,9 +194,9 @@ public function critical($message, array $context = []): bool * * @param string $message */ - public function error($message, array $context = []): bool + public function error(string|Stringable $message, array $context = []): void { - return $this->log('error', $message, $context); + $this->log('error', $message, $context); } /** @@ -206,9 +207,9 @@ public function error($message, array $context = []): bool * * @param string $message */ - public function warning($message, array $context = []): bool + public function warning(string|Stringable $message, array $context = []): void { - return $this->log('warning', $message, $context); + $this->log('warning', $message, $context); } /** @@ -216,9 +217,9 @@ public function warning($message, array $context = []): bool * * @param string $message */ - public function notice($message, array $context = []): bool + public function notice(string|Stringable $message, array $context = []): void { - return $this->log('notice', $message, $context); + $this->log('notice', $message, $context); } /** @@ -228,9 +229,9 @@ public function notice($message, array $context = []): bool * * @param string $message */ - public function info($message, array $context = []): bool + public function info(string|Stringable $message, array $context = []): void { - return $this->log('info', $message, $context); + $this->log('info', $message, $context); } /** @@ -238,9 +239,9 @@ public function info($message, array $context = []): bool * * @param string $message */ - public function debug($message, array $context = []): bool + public function debug(string|Stringable $message, array $context = []): void { - return $this->log('debug', $message, $context); + $this->log('debug', $message, $context); } /** @@ -249,7 +250,7 @@ public function debug($message, array $context = []): bool * @param string $level * @param string $message */ - public function log($level, $message, array $context = []): bool + public function log($level, string|Stringable $message, array $context = []): void { if (is_numeric($level)) { $level = array_search((int) $level, $this->logLevels, true); @@ -262,7 +263,7 @@ public function log($level, $message, array $context = []): bool // Does the app want to log this right now? if (! in_array($level, $this->loggableLevels, true)) { - return false; + return; } // Parse our placeholders @@ -295,8 +296,6 @@ public function log($level, $message, array $context = []): bool break; } } - - return true; } /** diff --git a/system/Test/TestLogger.php b/system/Test/TestLogger.php index 240f5c6d95b5..dce1277d98d2 100644 --- a/system/Test/TestLogger.php +++ b/system/Test/TestLogger.php @@ -12,6 +12,7 @@ namespace CodeIgniter\Test; use CodeIgniter\Log\Logger; +use Stringable; /** * @see \CodeIgniter\Test\TestLoggerTest @@ -27,7 +28,7 @@ class TestLogger extends Logger * @param string $level * @param string $message */ - public function log($level, $message, array $context = []): bool + public function log($level, string|Stringable $message, array $context = []): void { // While this requires duplicate work, we want to ensure // we have the final message to test against. @@ -52,7 +53,7 @@ public function log($level, $message, array $context = []): bool ]; // Let the parent do it's thing. - return parent::log($level, $message, $context); + parent::log($level, $message, $context); } /**