Class yii\log\Dispatcher
| 继承 | yii\log\Dispatcher » yii\base\Component » yii\base\BaseObject |
|---|---|
| 实现 | yii\base\Configurable |
| 可用版本自 | 2.0 |
| 源码 | https://github.com/yiichina/yii2/blob/api/framework/log/Dispatcher.php |
Dispatcher 管理一组 log targets。
Dispatcher 实现方法 dispatch() 将日志消息从 yii\log\Logger 转发到 $targets。
Dispatcher 的一个实例被注册为核心应用程序组件,可以使用 Yii::$app->log 进行访问。
您可以在应用程序配置中配置目标,如下所示:
[
'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',
],
],
],
],
],
]
每个日志目标都可以有一个名称,可以通过 $targets 属性引用,如下所示:
Yii::$app->log->targets['file']->enabled = false;
公共属性
| 属性 | 类型 | 描述 | 被定义在 |
|---|---|---|---|
| $behaviors | yii\base\Behavior[] | List of behaviors attached to this component | yii\base\Component |
| $flushInterval | integer | 记录多少消息后才将消息发送到目标。 此方法返回 yii\log\Logger::$flushInterval 的值。 | yii\log\Dispatcher |
| $logger | yii\log\Logger | 记录器 | yii\log\Dispatcher |
| $targets | array|yii\log\Target[] | 日志目标。 每个数组元素表示一个 log target 实例或用于创建日志目标实例的配置。 | yii\log\Dispatcher |
| $traceLevel | integer | 每个消息应记录多少应用程序调用堆栈。 此方法返回 yii\log\Logger::$traceLevel 的值。默认为 0。 | yii\log\Dispatcher |
公共方法
| 方法 | 描述 | 被定义在 |
|---|---|---|
| __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\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() | 将记录的消息调度到 $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() | 获取连接的记录器。 如果未设置,将使用 Yii::getLogger()。 | 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() | 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() | 设置连接的记录器。 | yii\log\Dispatcher |
| setTraceLevel() | yii\log\Dispatcher | |
| trigger() | Triggers an event. | yii\base\Component |
属性详情
记录多少消息后才将消息发送到目标。 此方法返回 yii\log\Logger::$flushInterval 的值。
记录器
日志目标。 每个数组元素表示一个 log target 实例或用于创建日志目标实例的配置。
每个消息应记录多少应用程序调用堆栈。 此方法返回 yii\log\Logger::$traceLevel 的值。默认为 0。
方法详情
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 |
将记录的消息调度到 $targets。
| public void dispatch($messages, $final) | ||
| $messages | array | 记录的消息 |
| $final | boolean | 是否在当前应用程序结束时调用此方法 |
| public integer getFlushInterval() | ||
| return | integer | 记录多少消息后才将消息发送到目标。 此方法返回 yii\log\Logger::$flushInterval 的值。 |
|---|---|---|
获取连接的记录器。 如果未设置,将使用 Yii::getLogger()。
| public yii\log\Logger getLogger() | ||
| return | yii\log\Logger | 记录器 |
|---|---|---|
| public integer getTraceLevel() | ||
| return | integer | 每个消息应记录多少应用程序调用堆栈。 此方法返回 yii\log\Logger::$traceLevel 的值。默认为 0。 |
|---|---|---|
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() |
| public void setFlushInterval($value) | ||
| $value | integer | 记录多少消息后才将消息发送到目标。 此方法设置 yii\log\Logger::$flushInterval 的值。 默认为 1000,表示每 1000 条消息执行一次 yii\log\Logger::flush() 方法。 如果您不希望在应用程序终止之前发送消息,请将此属性设置为 0。 此属性主要影响记录消息占用的内存量。 值越小意味着内存越少,但由于更加频繁的执行 yii\log\Logger::flush(),会增加执行时间。 |
设置连接的记录器。
| public void setLogger($value) | ||
| $value | yii\log\Logger|string|array | 要使用的记录器。 这可以是记录器实例,也可以是用于使用 Yii::createObject() 创建一个的配置。 |
| public void setTraceLevel($value) | ||
| $value | integer | 每个消息应记录多少应用程序调用堆栈。 此方法将设置 yii\log\Logger::$traceLevel 的值。如果该值大于 0,表示将记录该调用堆栈的最大数量。 请注意,只计算应用程序调用堆栈。 默认为 0。 |