Skip to content

Commit

Permalink
Allow Negating Categories in CLogRoutes
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh Priestly authored and unknown committed Sep 11, 2012
1 parent bfd756f commit dc89ce3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
1 change: 1 addition & 0 deletions framework/logging/CLogRoute.php
Expand Up @@ -40,6 +40,7 @@ abstract class CLogRoute extends CComponent
public $levels=''; public $levels='';
/** /**
* @var string list of categories separated by comma or space. Defaults to empty, meaning all categories. * @var string list of categories separated by comma or space. Defaults to empty, meaning all categories.
* Allows negating categories, use ! before a category name to not include it.
*/ */
public $categories=''; public $categories='';
/** /**
Expand Down
13 changes: 10 additions & 3 deletions framework/logging/CLogger.php
Expand Up @@ -149,13 +149,20 @@ public function getLogs($levels='',$categories='')
*/ */
private function filterByCategory($value) private function filterByCategory($value)
{ {
$cat=strtolower($value[2]);
$negateOnly=true;
foreach($this->_categories as $category) foreach($this->_categories as $category)
{ {
$cat=strtolower($value[2]); if (substr($category, 0,1) === '!')
$category = substr($category,1);
else
$negateOnly = false;

if($cat===$category || (($c=rtrim($category,'.*'))!==$category && strpos($cat,$c)===0)) if($cat===$category || (($c=rtrim($category,'.*'))!==$category && strpos($cat,$c)===0))
return true; return !$negateOnly;

} }
return false; return $negateOnly;
} }


/** /**
Expand Down

0 comments on commit dc89ce3

Please sign in to comment.