diff --git a/system/Debug/Toolbar/Collectors/Logs.php b/system/Debug/Toolbar/Collectors/Logs.php index f9fdabecbff1..92562e81e629 100644 --- a/system/Debug/Toolbar/Collectors/Logs.php +++ b/system/Debug/Toolbar/Collectors/Logs.php @@ -92,9 +92,13 @@ protected function collectLogs() return $this->data; } - $cache = service('logger')->logCache; + $logger = service('logger'); - $this->data = $cache ?? []; + if (! property_exists($logger, 'logCache')) { + return $this->data; + } + + $this->data = $logger->logCache; return $this->data; } diff --git a/tests/system/Debug/Toolbar/Collectors/LogsTest.php b/tests/system/Debug/Toolbar/Collectors/LogsTest.php index c239d0d422ba..a89fc878260c 100644 --- a/tests/system/Debug/Toolbar/Collectors/LogsTest.php +++ b/tests/system/Debug/Toolbar/Collectors/LogsTest.php @@ -18,6 +18,8 @@ use Config\Logger as LoggerConfig; use Config\Services; use PHPUnit\Framework\Attributes\Group; +use Psr\Log\AbstractLogger; +use Stringable; /** * @internal @@ -68,4 +70,18 @@ public function testNotEmpty(): void $collector = new Logs(); $this->assertFalse($collector->isEmpty()); } + + public function testEmptyWithThirdPartyLogger(): void + { + Services::injectMock('logger', new class () extends AbstractLogger { + public function log($level, string|Stringable $message, array $context = []): void + { + } + }); + + $collector = new Logs(); + + $this->assertTrue($collector->isEmpty()); + $this->assertSame(['logs' => []], $collector->display()); + } } diff --git a/user_guide_src/source/changelogs/v4.7.3.rst b/user_guide_src/source/changelogs/v4.7.3.rst index 06418cf9e5e8..e3600a814369 100644 --- a/user_guide_src/source/changelogs/v4.7.3.rst +++ b/user_guide_src/source/changelogs/v4.7.3.rst @@ -42,6 +42,7 @@ Bugs Fixed - **Common:** Fixed a bug where the ``command()`` helper function did not properly clean up output buffers, which could lead to risky tests when exceptions were thrown. - **Database:** Fixed a bug where the SQLSRV driver's decrement method was adding instead of subtracting the decrement value when ``$castTextToInt`` was false. - **Kint:** Fixed a bug where stale Content Security Policy nonces were reused in worker mode, causing browser CSP violations for Debug Toolbar assets. +- **Toolbar:** Fixed a bug where the Logs collector raised an undefined property error when using a third-party PSR-3 logger. - **Time:** Fixed a bug where ``Time::createFromTimestamp()`` could fail for microsecond timestamps when ``LC_NUMERIC`` used a comma decimal separator. - **Validation:** Fixed a bug where ``Validation::getValidated()`` dropped fields whose validated value was explicitly ``null``.