Skip to content

Commit b4b073e

Browse files
committed
fix: support third-party loggers in toolbar logs collector
1 parent 6c4acef commit b4b073e

2 files changed

Lines changed: 22 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
}

0 commit comments

Comments
 (0)