Skip to content

Commit 3405fc5

Browse files
authored
fix: support third-party loggers in toolbar logs collector (#10173)
1 parent 714c6d6 commit 3405fc5

3 files changed

Lines changed: 23 additions & 2 deletions

File tree

system/Debug/Toolbar/Collectors/Logs.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,13 @@ protected function collectLogs()
9292
return $this->data;
9393
}
9494

95-
$cache = service('logger')->logCache;
95+
$logger = service('logger');
9696

97-
$this->data = $cache ?? [];
97+
if (! property_exists($logger, 'logCache')) {
98+
return $this->data;
99+
}
100+
101+
$this->data = $logger->logCache;
98102

99103
return $this->data;
100104
}

tests/system/Debug/Toolbar/Collectors/LogsTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
use Config\Logger as LoggerConfig;
1919
use Config\Services;
2020
use PHPUnit\Framework\Attributes\Group;
21+
use Psr\Log\AbstractLogger;
22+
use Stringable;
2123

2224
/**
2325
* @internal
@@ -68,4 +70,18 @@ public function testNotEmpty(): void
6870
$collector = new Logs();
6971
$this->assertFalse($collector->isEmpty());
7072
}
73+
74+
public function testEmptyWithThirdPartyLogger(): void
75+
{
76+
Services::injectMock('logger', new class () extends AbstractLogger {
77+
public function log($level, string|Stringable $message, array $context = []): void
78+
{
79+
}
80+
});
81+
82+
$collector = new Logs();
83+
84+
$this->assertTrue($collector->isEmpty());
85+
$this->assertSame(['logs' => []], $collector->display());
86+
}
7187
}

user_guide_src/source/changelogs/v4.7.3.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ Bugs Fixed
4343
- **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.
4444
- **Database:** Fixed a bug where the SQLSRV driver's decrement method was adding instead of subtracting the decrement value when ``$castTextToInt`` was false.
4545
- **Kint:** Fixed a bug where stale Content Security Policy nonces were reused in worker mode, causing browser CSP violations for Debug Toolbar assets.
46+
- **Toolbar:** Fixed a bug where the Logs collector raised an undefined property error when using a third-party PSR-3 logger.
4647
- **Time:** Fixed a bug where ``Time::createFromTimestamp()`` could fail for microsecond timestamps when ``LC_NUMERIC`` used a comma decimal separator.
4748
- **Validation:** Fixed a bug where ``Validation::getValidated()`` dropped fields whose validated value was explicitly ``null``.
4849

0 commit comments

Comments
 (0)