Skip to content

Commit

Permalink
Added log category
Browse files Browse the repository at this point in the history
  • Loading branch information
mg-code committed Dec 15, 2014
1 parent 1ceccaf commit 3a07352
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions LoggingTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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);
}

/**
Expand All @@ -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);
}
}

0 comments on commit 3a07352

Please sign in to comment.