Skip to content

Latest commit

 

History

History
64 lines (52 loc) · 1.45 KB

logger.md

File metadata and controls

64 lines (52 loc) · 1.45 KB

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.

Collected data

Common

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"
    }
]

Summary

{
    "logger": {
        "total": 2
    }
}