@ -28,6 +28,7 @@ use yii\web\Request;
* @property int $levels The message levels that this target is interested in. This is a bitmap of level
* values. Defaults to 0, meaning all available levels. Note that the type of this property differs in getter
* and setter. See [[getLevels()]] and [[setLevels()]] for details.
* @property bool $enabled Whether to enable this log target. Defaults to true.
*
* For more details and usage information on Target, see the [guide article on logging & targets](guide:runtime-logging).
*
@ -37,10 +38,6 @@ use yii\web\Request;
abstract class Target extends Component
{
/**
* @var bool whether to enable this log target. Defaults to true.
*/
public $enabled = true;
/**
* @var array 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
@ -94,7 +91,7 @@ abstract class Target extends Component
public $messages = [];
private $_levels = 0;
private $_enabled = true;
/**
* Exports log [[messages]] to a specific destination.
@ -311,4 +308,28 @@ abstract class Target extends Component
return "[$ip][$userID][$sessionID]";
}
/**
* Sets a value indicating whether this log target is enabled.
* @param bool|callable $value a boolean value or a callable to obtain the value from.
* The callable value is available since version 2.0.13.
*/
public function setEnabled($value)
{
$this->_enabled = $value;
}
/**
* Check whether the log target is enabled.
* @property Indicates whether this log target is enabled. Defaults to true.
* @return bool A value indicating whether this log target is enabled.
*/
public function getEnabled()
{
if (is_callable($this->_enabled)) {
return call_user_func($this->_enabled, $this);
}
return $this->_enabled;
}
}