PsrLogger
API reference › yii › log › PsrLogger
Adapts PSR-3 log calls to a Yii logger.
When no Yii logger is passed to the constructor, the current logger returned by Yii::getLogger() is resolved
for every call. This ensures that replacing the global Yii logger does not leave this adapter with a stale reference.
Methods
Section titled “Methods”| Method | Description | Defined by |
|---|---|---|
__construct() | PsrLogger | |
getLogger() | Returns the configured Yii logger or the current global logger. | PsrLogger |
log() | Logs with an arbitrary level. | PsrLogger |
Constants
Section titled “Constants”| Constant | Value | Description | Defined by |
|---|---|---|---|
DEFAULT_LEVEL_MAP | [\ | Default mapping from PSR-3 levels to Yii log levels. | PsrLogger |
Method details
Section titled “Method details”__construct()
Section titled “__construct() ”public function __construct(yii\log\Logger|null $logger = null, array<string, int> $levelMap = \self::DEFAULT_LEVEL_MAP, string $category = 'application')Parameters
| Parameter | Type | Description |
|---|---|---|
$logger | Logger| | Yii logger to use. null resolves the current global Yii logger for every call. |
$levelMap | array<string, | Mapping from supported PSR-3 levels to Yii log levels. |
$category | string | Default Yii log category. A string category context value overrides it for that call. |
getLogger()
Section titled “getLogger() ”public function getLogger(): yii\log\LoggerReturns the configured Yii logger or the current global logger.
Returns
log()
Section titled “log() ”public function log(mixed $level, Stringable|string $message, array<array-key, mixed> $context = []): voidLogs with an arbitrary level.
Parameters
| Parameter | Type | Description |
|---|---|---|
$level | mixed | |
$message | Stringable| | |
$context | array<array-key, |
Throws
Psr\Log\InvalidArgumentException: If the level is not supported.