Class yii\log\Dispatcher
Inheritance | yii\log\Dispatcher » yii\base\Component » yii\base\BaseObject |
---|---|
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' => 'admin@example.com',
],
],
],
],
],
]
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\Component |
__clone() | This method is called after the object is created by cloning an existing one. | yii\base\Component |
__construct() | {@inheritdoc} | yii\log\Dispatcher |
__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\BaseObject |
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\Component |
hasProperty() | Returns a value indicating whether a property is defined for this component. | yii\base\Component |
init() | {@inheritdoc} | 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
How many messages should be logged before they are sent to targets. This method returns the value of yii\log\Logger::$flushInterval.
The logger.
The log targets. Each array element represents a single log target instance or the configuration for creating the log target instance.
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.
Method Details
{@inheritdoc}
public void __construct ( $config = [] ) | ||
$config |
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 |
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. |
---|
Gets the connected logger.
If not set, Yii::getLogger() will be used.
public yii\log\Logger getLogger ( ) | ||
return | yii\log\Logger | The logger. |
---|
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. |
---|
{@inheritdoc}
public void init ( ) |
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(). |
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(). |
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. |
Signup or Login in order to comment.