Abstract Class yii\log\Target
Inheritance | yii\log\Target » yii\base\Component » yii\base\Object |
---|---|
Implements | yii\base\Configurable |
Subclasses | yii\debug\LogTarget, yii\log\DbTarget, yii\log\EmailTarget, yii\log\FileTarget, yii\log\SyslogTarget |
Available since version | 2.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
Property | Type | Description | Defined 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
Method | Description | Defined By |
---|---|---|
__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 |
__construct() | Constructor. | yii\base\Object |
__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() | 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\Component |
hasProperty() | Returns a value indicating whether a property is defined for this component. | yii\base\Component |
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
Method | Description | Defined By |
---|---|---|
getContextMessage() | Generates the context information to be logged. | yii\log\Target |
Property Details
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'.
Whether to enable this log target. Defaults to true.
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.
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.
The message levels that this target is interested in. This is a bitmap of level values. Defaults to 0, meaning all available levels.
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']
.
Since version 2.0.9 additional syntax can be used: Each element could be specified as one of the following:
var
-var
will be logged.var.key
- onlyvar[key]
key will be logged.!var.key
-var[key]
key will be excluded.
See also yii\helpers\ArrayHelper::filter().
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.
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
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).
public 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 |
Exports log $messages to a specific destination.
Child classes must implement this method.
public abstract void export ( ) |
Filters the given messages according to their categories and levels.
public static 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. |
---|
Formats a log message for display as a string.
public 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 |
---|
Generates the context information to be logged.
The default implementation will dump user information, system variables, etc.
protected string getContextMessage ( ) | ||
return | string | The context information. If an empty string, it means no context information. |
---|
public 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. |
---|
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.
public string getMessagePrefix ( $message ) | ||
$message | array | The message being exported. The message structure follows that in yii\log\Logger::$messages. |
return | string | The prefix string |
---|
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
public void setLevels ( $levels ) | ||
$levels | array|integer | Message levels that this target is interested in. |
throws | yii\base\InvalidConfigException | if $levels value is not correct. |
---|