diff --git a/LoggingTrait.php b/LoggingTrait.php index cf360c4..ef45327 100644 --- a/LoggingTrait.php +++ b/LoggingTrait.php @@ -9,12 +9,29 @@ * Usually this trait is used for CLI commands. * You can simply disable message output by calling in class: $this->msgLoggingEnabled = false * @property bool $msgLoggingEnabled + * @property string $loggingCategory the category of logging messages. */ trait LoggingTrait { /** @var bool Whether to output logging messages */ protected $_msgLoggingEnabled = true; + /** @var string */ + protected $_loggingCategory = 'application'; + + public function setLoggingCategory($value) + { + $this->_loggingCategory = $value; + } + + /** + * @return bool + */ + public function getLoggingCategory() + { + return $this->_loggingCategory; + } + /** * @return bool */ @@ -76,7 +93,7 @@ public function logError($msg) { $this->msg($msg); $msg = get_class($this).' Error: '.$msg; - \Yii::error($msg, 'app\modules\crawler'); + \Yii::error($msg, $this->_loggingCategory); } /** @@ -88,6 +105,6 @@ public function logException($exception) { $this->msg($exception->getMessage()); $msg = get_class($this).' exception: '.$exception->getMessage()." ".PHP_EOL.$exception->getTraceAsString(); - \Yii::error($msg, 'app\modules\crawler'); + \Yii::error($msg, $this->_loggingCategory); } }