* @since 2.0 */ class LogPanel extends Panel { public function getName() { return 'Logs'; } public function getSummary() { $output = ['' . count($this->data['messages']) . '']; $title = 'Logged ' . count($this->data['messages']) . ' messages'; $errorCount = count(Target::filterMessages($this->data['messages'], Logger::LEVEL_ERROR)); if ($errorCount) { $output[] = '' . $errorCount . ''; $title .= ", $errorCount errors"; } $warningCount = count(Target::filterMessages($this->data['messages'], Logger::LEVEL_WARNING)); if ($warningCount) { $output[] = '' . $warningCount . ''; $title .= ", $warningCount warnings"; } $log = implode(' ', $output); $url = $this->getUrl(); return << Log $log EOD; } public function getDetail() { $rows = []; foreach ($this->data['messages'] as $log) { list ($message, $level, $category, $time, $traces) = $log; $time = date('H:i:s.', $time) . sprintf('%03d', (int)(($time - (int)$time) * 1000)); $message = nl2br(Html::encode($message)); if (!empty($traces)) { $message .= Html::ul($traces, [ 'class' => 'trace', 'item' => function ($trace) { return "
  • {$trace['file']}({$trace['line']})
  • "; }, ]); } if ($level == Logger::LEVEL_ERROR) { $class = ' class="danger"'; } elseif ($level == Logger::LEVEL_WARNING) { $class = ' class="warning"'; } elseif ($level == Logger::LEVEL_INFO) { $class = ' class="success"'; } else { $class = ''; } $level = Logger::getLevelName($level); $rows[] = "$time$level$category
    $message
    "; } $rows = implode("\n", $rows); return <<Log Messages $rows
    Time Level Category Message
    EOD; } public function save() { $target = $this->module->logTarget; $messages = $target->filterMessages($target->messages, Logger::LEVEL_ERROR | Logger::LEVEL_INFO | Logger::LEVEL_WARNING | Logger::LEVEL_TRACE); return ['messages' => $messages]; } }