filterMessages() public static method

Filters the given messages according to their categories and levels.
public static filterMessages ( array $messages, integer $levels, array $categories = [], array $except = [] ) : array
$messages array messages to be filtered. The message structure follows that in [[Logger::messages]].
$levels integer the message levels to filter by. This is a bitmap of level values. Value 0 means allowing all levels.
$categories array the message categories to filter by. If empty, it means all categories are allowed.
$except array the message categories to exclude. If empty, it means all categories are allowed.
return array the filtered messages.
Example #1
0
 /**
  * Filter all exceptions. They're logged via ErrorHandler
  * @inheritdoc
  */
 public static function filterMessages($messages, $levels = 0, $categories = [], $except = [])
 {
     $messages = parent::filterMessages($messages, $levels, $categories, $except);
     foreach ($messages as $i => $message) {
         $type = explode(':', $message[2]);
         // shutdown function not working in yii2 yet: https://github.com/yiisoft/yii2/issues/6637
         // allow fatal errors exceptions in log messages
         if (is_array($type) && sizeof($type) == 2 && $type[0] == 'yii\\base\\ErrorException' && ErrorException::isFatalError(['type' => $type[1]])) {
             continue;
         }
         if (is_string($message[0]) && strpos($message[0], 'exception \'') === 0) {
             unset($messages[$i]);
         }
     }
     return $messages;
 }
Example #2
0
<?php

use yii\log\Target;
use yii\log\Logger;
?>

<?php 
$title = 'Logged ' . count($data['messages']) . ' messages';
$errorCount = count(Target::filterMessages($data['messages'], Logger::LEVEL_ERROR));
$warningCount = count(Target::filterMessages($data['messages'], Logger::LEVEL_WARNING));
$output = [];
if ($errorCount) {
    $output[] = "<span class=\"label label-important\">{$errorCount}</span>";
    $title .= ", {$errorCount} errors";
}
if ($warningCount) {
    $output[] = "<span class=\"label label-warning\">{$warningCount}</span>";
    $title .= ", {$warningCount} warnings";
}
?>

<div class="yii-debug-toolbar-block">
    <a href="<?php 
echo $panel->getUrl();
?>
" title="<?php 
echo $title;
?>
">Log
        <span class="label"><?php 
echo count($data['messages']);