Class yii\log\Dispatcher
| Inheritance | yii\log\Dispatcher » yii\base\Component » yii\base\Object |
|---|---|
| Implements | yii\base\Configurable |
| Available since version | 2.0 |
| Source Code | https://github.com/yiisoft/yii2/blob/master/framework/log/Dispatcher.php |
Dispatcher manages a set of log targets.
Dispatcher implements the dispatch()-method that forwards the log messages from a yii\log\Logger to the registered log $targets.
An instance of Dispatcher is registered as a core application component and can be accessed using Yii::$app->log.
You may configure the targets in application configuration, like the following:
[
'components' => [
'log' => [
'targets' => [
'file' => [
'class' => 'yii\log\FileTarget',
'levels' => ['trace', 'info'],
'categories' => ['yii\*'],
],
'email' => [
'class' => 'yii\log\EmailTarget',
'levels' => ['error', 'warning'],
'message' => [
'to' => '[email protected]',
],
],
],
],
],
]
Each log target can have a name and can be referenced via the $targets property as follows:
Yii::$app->log->targets['file']->enabled = false;
Public Properties
| Property | Type | Description | Defined By |
|---|---|---|---|
| $behaviors | yii\base\Behavior[] | List of behaviors attached to this component | yii\base\Component |
| $flushInterval | integer | How many messages should be logged before they are sent to targets. | yii\log\Dispatcher |
| $logger | yii\log\Logger | The logger. | yii\log\Dispatcher |
| $targets | array|yii\log\Target[] | The log targets. | yii\log\Dispatcher |
| $traceLevel | integer | How many application call stacks should be logged together with each message. | yii\log\Dispatcher |
Public Methods
| Method | Description | Defined 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\log\Dispatcher |
| __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 |
| detachBehavior() | Detaches a behavior from the component. | yii\base\Component |
| detachBehaviors() | Detaches all behaviors from the component. | yii\base\Component |
| dispatch() | Dispatches the logged messages to $targets. | yii\log\Dispatcher |
| ensureBehaviors() | Makes sure that the behaviors declared in behaviors() are attached to this component. | yii\base\Component |
| getBehavior() | Returns the named behavior object. | yii\base\Component |
| getBehaviors() | Returns all behaviors attached to this component. | yii\base\Component |
| getFlushInterval() | yii\log\Dispatcher | |
| getLogger() | Gets the connected logger. | yii\log\Dispatcher |
| getTraceLevel() | yii\log\Dispatcher | |
| 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\log\Dispatcher |
| off() | Detaches an existing event handler from this component. | yii\base\Component |
| on() | Attaches an event handler to an event. | yii\base\Component |
| setFlushInterval() | yii\log\Dispatcher | |
| setLogger() | Sets the connected logger. | yii\log\Dispatcher |
| setTraceLevel() | yii\log\Dispatcher | |
| trigger() | Triggers an event. | yii\base\Component |
Property Details
$flushInterval public property
How many messages should be logged before they are sent to targets. This method returns the value of yii\log\Logger::$flushInterval.
public integer getFlushInterval ( )
public void setFlushInterval ( $value )
$logger public property
The logger.
public yii\log\Logger getLogger ( )
public void setLogger ( $value )
$targets public property
The log targets. Each array element represents a single log target instance or the configuration for creating the log target instance.
public array|yii\log\Target[] $targets = []
$traceLevel public property
How many application call stacks should be logged together with each message. This method returns the value of yii\log\Logger::$traceLevel. Defaults to 0.
public integer getTraceLevel ( )
public void setTraceLevel ( $value )
Method Details
__construct() public method
Constructor.
The default implementation does two things:
- Initializes the object with the given configuration
$config. - Call init().
If this method is overridden in a child class, it is recommended that
- the last parameter of the constructor is a configuration array, like
$confighere. - call the parent implementation at the end of the constructor.
| public void __construct ( $config = [] ) | ||
|---|---|---|
| $config | array |
Name-value pairs that will be used to initialize the object properties |
dispatch() public method
Dispatches the logged messages to $targets.
| public void dispatch ( $messages, $final ) | ||
|---|---|---|
| $messages | array |
The logged messages |
| $final | boolean |
Whether this method is called at the end of the current application |
getFlushInterval() public method
| public integer getFlushInterval ( ) | ||
|---|---|---|
| return | integer |
How many messages should be logged before they are sent to targets. This method returns the value of yii\log\Logger::$flushInterval. |
getLogger() public method
Gets the connected logger.
If not set, Yii::getLogger() will be used.
| public yii\log\Logger getLogger ( ) | ||
|---|---|---|
| return | yii\log\Logger |
The logger. |
getTraceLevel() public method
| public integer getTraceLevel ( ) | ||
|---|---|---|
| return | integer |
How many application call stacks should be logged together with each message. This method returns the value of yii\log\Logger::$traceLevel. Defaults to 0. |
init() public method
Initializes the object.
This method is invoked at the end of the constructor after the object is initialized with the given configuration.
| public void init ( ) |
|---|
setFlushInterval() public method
| public void setFlushInterval ( $value ) | ||
|---|---|---|
| $value | integer |
How many messages should be logged before they are sent to targets. This method will set the value of yii\log\Logger::$flushInterval. Defaults to 1000, meaning the yii\log\Logger::flush() method will be invoked once every 1000 messages logged. Set this property to be 0 if you don't want to flush messages until the application terminates. This property mainly affects how much memory will be taken by the logged messages. A smaller value means less memory, but will increase the execution time due to the overhead of yii\log\Logger::flush(). |
setLogger() public method
Sets the connected logger.
| public void setLogger ( $value ) | ||
|---|---|---|
| $value | yii\log\Logger|string|array |
The logger to be used. This can either be a logger instance or a configuration that will be used to create one using Yii::createObject(). |
setTraceLevel() public method
| public void setTraceLevel ( $value ) | ||
|---|---|---|
| $value | integer |
How many application call stacks should be logged together with each message. This method will set the value of yii\log\Logger::$traceLevel. If the value is greater than 0, at most that number of call stacks will be logged. Note that only application call stacks are counted. Defaults to 0. |
© 2008–2017 by Yii Software LLC
Licensed under the three clause BSD license.
http://www.yiiframework.com/doc-2.0/yii-log-dispatcher.html