vjik / yii2-psr-logger-proxy
PSR-3 compatible logger proxy for Yii2
1.0.0
2020-08-02 10:51 UTC
Requires
- psr/log: ^1.1
- yiisoft/yii2: ~2.0.0
Requires (Dev)
- phpunit/phpunit: ^7.5
This package is auto-updated.
Last update: 2024-10-29 05:47:25 UTC
README
Installation
The preferred way to install this extension is through composer:
composer require vjik/yii2-psr-logger-proxy
Base usage
use Vjik\Yii2\Psr\LoggerProxy\LoggerProxy; $loggerProxy = new LoggerProxy(\Yii::getLogger());
Advanced usage
use Vjik\Yii2\Psr\LoggerProxy\LoggerProxy; // Create proxy $loggerProxy = new LoggerProxy(\Yii::getLogger()); // Set default Yii2 log category (default "application") $loggerProxy->setDefaultCategory('psr-3'); // Add PSR-3 log context params for use as Yii2 log category $loggerProxy->addCategoryParam('category'); $loggerProxy->addCategoryParam('type'); // Set custom function for prepare PSR-3 log message tot Yii2 log message // Return message or NULL for use internal prepare message function. $loggerProxy->setPrepareMessage(function ($message, $context) { if (isset($context['elapsed'])) { return 'Query (' . $context['elapsed'] . ' ms):' . "\n" . $message; } return null; });