Abstract Class yii\log\Target

Inheritanceyii\log\Target » yii\base\Component » yii\base\Object
Implementsyii\base\Configurable
Subclassesyii\debug\LogTarget, yii\log\DbTarget, yii\log\EmailTarget, yii\log\FileTarget, yii\log\SyslogTarget, yii\mongodb\log\MongoDbTarget
Available since version2.0
Source Code https://github.com/yiisoft/yii2/blob/master/framework/log/Target.php

Target is the base class for all log target classes.

A log target object will filter the messages logged by yii\log\Logger according to its $levels and $categories properties. It may also export the filtered messages to specific destination defined by the target, such as emails, files.

Level filter and category filter are combinatorial, i.e., only messages satisfying both filter conditions will be handled. Additionally, you may specify $except to exclude messages of certain categories.

Public Properties

Hide inherited properties

PropertyTypeDescriptionDefined By
$behaviors yii\base\Behavior[] List of behaviors attached to this component yii\base\Component
$categories array List of message categories that this target is interested in. yii\log\Target
$enabled boolean Whether to enable this log target. yii\log\Target
$except array List of message categories that this target is NOT interested in. yii\log\Target
$exportInterval integer How many messages should be accumulated before they are exported. yii\log\Target
$levels integer The message levels that this target is interested in. yii\log\Target
$logVars array List of the PHP predefined variables that should be logged in a message. yii\log\Target
$messages array The messages that are retrieved from the logger so far by this log target. yii\log\Target
$prefix callable A PHP callable that returns a string to be prefixed to every exported message. yii\log\Target

Public Methods

Hide inherited methods

MethodDescriptionDefined By
__call() Calls the named method which is not a class method. yii\base\Object
__clone() This method is called after the object is created by cloning an existing one. yii\base\Component
__construct() Constructor. yii\base\Object
__get() Returns the value of an object property. yii\base\Object
__isset() Checks if a property is set, i.e. defined and not null. yii\base\Object
__set() Sets value of an object property. yii\base\Object
__unset() Sets an object property to null. yii\base\Object
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\Object
canSetProperty() Returns a value indicating whether a property can be set. yii\base\Object
className() Returns the fully qualified name of this class. yii\base\Object
collect() Processes the given log messages. yii\log\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 log $messages to a specific destination. yii\log\Target
filterMessages() Filters the given messages according to their categories and levels. yii\log\Target
formatMessage() Formats a log message for display as a string. yii\log\Target
getBehavior() Returns the named behavior object. yii\base\Component
getBehaviors() Returns all behaviors attached to this component. yii\base\Component
getLevels() yii\log\Target
getMessagePrefix() Returns a string to be prefixed to the given message. yii\log\Target
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\Object
hasProperty() Returns a value indicating whether a property is defined. yii\base\Object
init() Initializes the object. yii\base\Object
off() Detaches an existing event handler from this component. yii\base\Component
on() Attaches an event handler to an event. yii\base\Component
setLevels() Sets the message levels that this target is interested in. yii\log\Target
trigger() Triggers an event. yii\base\Component

Protected Methods

Hide inherited methods

MethodDescriptionDefined By
getContextMessage() Generates the context information to be logged. yii\log\Target

Property Details

$categories public property

List of message categories that this target is interested in. Defaults to empty, meaning all categories. You can use an asterisk at the end of a category so that the category may be used to match those categories sharing the same common prefix. For example, 'yii\db*' will match categories starting with 'yii\db\', such as 'yii\db\Connection'.

$enabled public property

Whether to enable this log target. Defaults to true.

$except public property

List of message categories that this target is NOT interested in. Defaults to empty, meaning no uninteresting messages. If this property is not empty, then any category listed here will be excluded from $categories. You can use an asterisk at the end of a category so that the category can be used to match those categories sharing the same common prefix. For example, 'yii\db*' will match categories starting with 'yii\db\', such as 'yii\db\Connection'.

See also $categories.

$exportInterval public property

How many messages should be accumulated before they are exported. Defaults to 1000. Note that messages will always be exported when the application terminates. Set this property to be 0 if you don't want to export messages until the application terminates.

$levels public property
integer getLevels( )
void setLevels$levels )

The message levels that this target is interested in. This is a bitmap of level values. Defaults to 0, meaning all available levels.

$logVars public property
array $logVars = ['_GET''_POST''_FILES''_COOKIE''_SESSION''_SERVER']

List of the PHP predefined variables that should be logged in a message. Note that a variable must be accessible via $GLOBALS. Otherwise it won't be logged. Defaults to ['_GET', '_POST', '_FILES', '_COOKIE', '_SESSION', '_SERVER'].

$messages public property

The messages that are retrieved from the logger so far by this log target. Please refer to yii\log\Logger::$messages for the details about the message structure.

$prefix public property

A PHP callable that returns a string to be prefixed to every exported message.

If not set, getMessagePrefix() will be used, which prefixes the message with context information such as user IP, user ID and session ID.

The signature of the callable should be function ($message).

Method Details

collect() public method

Processes the given log messages.

This method will filter the given messages with $levels and $categories. And if requested, it will also export the filtering result to specific medium (e.g. email).

void collect$messages$final )
$messages array

Log messages to be processed. See yii\log\Logger::$messages for the structure of each message.

$final boolean

Whether this method is called at the end of the current application

export() public method

Exports log $messages to a specific destination.

Child classes must implement this method.

void export( )
filterMessages() public method

Filters the given messages according to their categories and levels.

array filterMessages$messages$levels 0$categories = [], $except = [] )
$messages array

Messages to be filtered. The message structure follows that in yii\log\Logger::$messages.

$levels integer

The message levels to filter by. This is a bitmap of level values. Value 0 means allowing all levels.

$categories array

The message categories to filter by. If empty, it means all categories are allowed.

$except array

The message categories to exclude. If empty, it means all categories are allowed.

return array

The filtered messages.

formatMessage() public method

Formats a log message for display as a string.

string formatMessage$message )
$message array

The log message to be formatted. The message structure follows that in yii\log\Logger::$messages.

return string

The formatted message

getContextMessage() protected method

Generates the context information to be logged.

The default implementation will dump user information, system variables, etc.

string getContextMessage( )
return string

The context information. If an empty string, it means no context information.

getLevels() public method

integer getLevels( )
return integer

The message levels that this target is interested in. This is a bitmap of level values. Defaults to 0, meaning all available levels.

getMessagePrefix() public method

Returns a string to be prefixed to the given message.

If $prefix is configured it will return the result of the callback. The default implementation will return user IP, user ID and session ID as a prefix.

string getMessagePrefix$message )
$message array

The message being exported. The message structure follows that in yii\log\Logger::$messages.

return string

The prefix string

setLevels() public method

Sets the message levels that this target is interested in.

The parameter can be either an array of interested level names or an integer representing the bitmap of the interested level values. Valid level names include: 'error', 'warning', 'info', 'trace' and 'profile'; valid level values include: yii\log\Logger::LEVEL_ERROR, yii\log\Logger::LEVEL_WARNING, yii\log\Logger::LEVEL_INFO, yii\log\Logger::LEVEL_TRACE and yii\log\Logger::LEVEL_PROFILE.

For example,

['error', 'warning']
// which is equivalent to:
Logger::LEVEL_ERROR | Logger::LEVEL_WARNING
void setLevels$levels )
$levels array|integer

Message levels that this target is interested in.

throws yii\base\InvalidConfigException

if an unknown level name is given