LogCollector
collects all data logged by \Psr\Log\LoggerInterface
.
It uses \Yiisoft\Yii\Debug\Collector\LoggerInterfaceProxy
proxy to wrap the original PSR-3 logger and proxy all calls to the collector.
Example:
final class SiteController
{
public function __construct(private ViewRenderer $viewRenderer)
{
$this->viewRenderer = $viewRenderer->withController($this);
}
public function index(LoggerInterface $logger): ResponseInterface
{
$logger->debug('Hello, world!', ['category' => 'debug']);
$logger->info('Hello, world!', ['category' => 'info']);
return $this->viewRenderer->render('index');
}
}
Output:
[
{
"time": 1704544908.712395,
"level": "debug",
"message": "Hello, world!",
"context": {
"category": "debug"
},
"line": ".../demo\/blog\/src\/Controller\/SiteController.php:21"
},
{
"time": 1704544908.712417,
"level": "info",
"message": "Hello, world!",
"context": {
"category": "info"
},
"line": ".../demo\/blog\/src\/Controller\/SiteController.php:22"
}
]
{
"logger": {
"total": 2
}
}