Skip to content
PHP Ecosystem
Explore

PsrTarget

API reference › yii › log › PsrTarget

classyii\log\PsrTarget
ExtendsTarget » yii\base\Component » yii\base\BaseObject
Implementsyii\base\Configurable
Since22.0
Sourceframework/log/PsrTarget.php

Exports Yii log messages to a PSR-3 logger.

The Yii category, trace, and memory usage are passed as PSR-3 context. The original Yii timestamp can also be added by enabling $addTimestampToContext. Context keys carried by a round-tripped PsrMessage take precedence: trace, memory, category, and timestamp are only added when the original context does not define them, and trace only when Yii collected traces. $extractExceptionTrace deliberately overwrites trace when enabled.

PropertyTypeDescriptionDefined by
$addTimestampToContextboolWhether to add the original Yii log timestamp to the PSR-3 context. Default: false.PsrTarget
$behaviors read-onlyarray<yii\base\Behavior<static>>List of behaviors attached to this component.yii\base\Component
$categorieslist<string>List of message categories that this target is interested in. Default: [].Target
$enabledbool|callableA boolean value or a callable to obtain the value from.Target
$exceptlist<string>List of message categories that this target is NOT interested in. Default: [].Target
$exportIntervalintHow many messages should be accumulated before they are exported. Default: 1000.Target
$extractExceptionTraceboolWhether to export an exception message and trace separately instead of stringifying the exception. Default: false.PsrTarget
$levelMaparray<int, string>Mapping from Yii levels to PSR-3 levels. Default: [\yii\log\Logger::LEVEL_ERROR => \Psr\Log\LogLevel::ERROR, \yii\log\Logger::LEVEL_WARNING => \Psr\Log\LogLevel::WARNING, \yii\log\Logger::LEVEL_INFO => \Psr\Log\LogLevel::INFO, \yii\log\Logger::LEVEL_TRACE => \Psr\Log\LogLevel::DEBUG, \yii\log\Logger::LEVEL_PROFILE => \Psr\Log\LogLevel::DEBUG, \yii\log\Logger::LEVEL_PROFILE_BEGIN => \Psr\Log\LogLevel::DEBUG, \yii\log\Logger::LEVEL_PROFILE_END => \Psr\Log\LogLevel::DEBUG].PsrTarget
$levelsarray|intMessage levels that this target is interested in.Target
$loggerPsr\Log\LoggerInterfaceThe PSR-3 logger used to export messages.PsrTarget
$logVarslist<string>List of the PHP predefined variables that should be logged in a message. Default: ['_GET', '_POST', '_FILES', '_COOKIE', '_SESSION', '_SERVER'].Target
$maskVarslist<string>List of the PHP predefined variables that should NOT be logged “as is” and should always be replaced with a mask *** before logging, when exist. Default: ['_SERVER.HTTP_AUTHORIZATION', '_SERVER.PHP_AUTH_USER', '_SERVER.PHP_AUTH_PW']. Available since 2.0.16.Target
$messageslist<yii\log\LogMessage>The messages that are retrieved from the logger so far by this log target. Default: [].Target
$microtimeboolWhether to log time with microseconds. Default: false. Available since 2.0.13.Target
$prefixcallable(yii\log\LogMessage): string|nullA PHP callable that returns a string to be prefixed to every exported message. Default: null.Target
$psrLevelslist<string>|nullExact PSR-3 levels this target exports after Yii level and category filtering. null means all PSR-3 levels.PsrTarget
MethodDescriptionDefined by
__construct()Constructor.yii\base\BaseObject
__call()Calls the named method which is not a class method.yii\base\Component
__clone()This method is called after the object is created by cloning an existing one.yii\base\Component
__get()Returns the value of a component property.yii\base\Component
__isset()Checks if a property is set, i.e. defined and not null.yii\base\Component
__set()Sets the value of a component property.yii\base\Component
__unset()Sets a component property to be null.yii\base\Component
attachBehavior()Attaches a behavior to this component.yii\base\Component
attachBehaviors()Attaches a list of behaviors to the component.yii\base\Component
behaviors()Returns a list of behaviors that this component should behave as.yii\base\Component
canGetProperty()Returns a value indicating whether a property can be read.yii\base\Component
canSetProperty()Returns a value indicating whether a property can be set.yii\base\Component
className() staticReturns the fully qualified name of this class.yii\base\BaseObject
collect()Processes the given log messages.Target
detachBehavior()Detaches a behavior from the component.yii\base\Component
detachBehaviors()Detaches all behaviors from the component.yii\base\Component
ensureBehaviors()Makes sure that the behaviors declared in behaviors() are attached to this component.yii\base\Component
export()Exports accumulated messages to the configured PSR-3 logger.PsrTarget
filterMessages() staticFilters the given messages according to their categories and levels.Target
formatMessage()Formats a log message for display as a string.Target
getBehavior()Returns the named behavior object.yii\base\Component
getBehaviors()Returns all behaviors attached to this component.yii\base\Component
getEnabled()Check whether the log target is enabled.Target
getLevels()Target
getLogger()Returns the configured PSR-3 logger.PsrTarget
getMessagePrefix()Returns a string to be prefixed to the given message.Target
getPsrLevels()Returns the exact PSR-3 levels this target exports.PsrTarget
hasEventHandlers()Returns a value indicating whether there is any handler attached to the named event.yii\base\Component
hasMethod()Returns a value indicating whether a method is defined.yii\base\Component
hasProperty()Returns a value indicating whether a property is defined for this component.yii\base\Component
init()Initializes the object.PsrTarget
off()Detaches an existing event handler from this component.yii\base\Component
on()Attaches an event handler to an event.yii\base\Component
setEnabled()Sets a value indicating whether this log target is enabled.Target
setLevels()Sets the message levels that this target is interested in.Target
setLogger()Sets the PSR-3 logger.PsrTarget
setPsrLevels()Sets the exact PSR-3 levels this target exports after normal Yii target filtering.PsrTarget
trigger()Triggers an event.yii\base\Component
formatMessageText() protectedConverts a log message value to text.Target
getContextMessage() protectedGenerates the context information to be logged.Target
getTime() protectedReturns formatted (‘Y-m-d H:i:s’) timestamp for message.Target
resolvePsrLevel() protectedResolves the PSR-3 level for a Yii message.PsrTarget
public function export(): void

Exports accumulated messages to the configured PSR-3 logger.

public function getLogger(): Psr\Log\LoggerInterface

Returns the configured PSR-3 logger.

Returns

Psr\Log\LoggerInterface

Throws

public function getPsrLevels(): list<string>|null

Returns the exact PSR-3 levels this target exports.

Returns

list<string>|null: null means all PSR-3 levels.

public function init(): mixed

Initializes the object.

This method is invoked at the end of the constructor after the object is initialized with the given configuration.

Returns

mixed

public function setLogger(Psr\Log\LoggerInterface $logger): void

Sets the PSR-3 logger.

Parameters

ParameterTypeDescription
$loggerPsr\Log\LoggerInterface

Throws

public function setPsrLevels(list<string>|null $levels): void

Sets the exact PSR-3 levels this target exports after normal Yii target filtering.

Parameters

ParameterTypeDescription
$levelslist<string>|nullnull or an empty array enables all PSR-3 levels.

Throws

protected function resolvePsrLevel(array $message): string

Resolves the PSR-3 level for a Yii message.

Parameters

ParameterTypeDescription
$messagearrayYii log message.

Returns

string

Throws