* @since 2.0
*/
class LogPanel extends Panel
{
public function getName()
{
return 'Logs';
}
public function getSummary()
{
$output = array();
$errorCount = count(Target::filterMessages($this->data['messages'], Logger::LEVEL_ERROR));
if ($errorCount) {
$output[] = '' . $errorCount . ' ' . ($errorCount > 1 ? 'errors' : 'error');
}
$warningCount = count(Target::filterMessages($this->data['messages'], Logger::LEVEL_WARNING));
if ($warningCount) {
$output[] = '' . $warningCount . ' ' . ($warningCount > 1 ? 'warnings' : 'warning');
}
if (!empty($output)) {
$log = implode(', ', $output);
$url = $this->getUrl();
return <<
$log
EOD;
} else {
return '';
}
}
public function getDetail()
{
$rows = array();
foreach ($this->data['messages'] as $log) {
$time = date('H:i:s.', $log[3]) . sprintf('%03d', (int)(($log[3] - (int)$log[3]) * 1000));
$level = Logger::getLevelName($log[1]);
$message = Html::encode(wordwrap($log[0]));
if ($log[1] == Logger::LEVEL_ERROR) {
$class = ' class="error"';
} elseif ($log[1] == Logger::LEVEL_WARNING) {
$class = ' class="warning"';
} elseif ($log[1] == Logger::LEVEL_INFO) {
$class = ' class="info"';
} else {
$class = '';
}
$rows[] = "$time | $level | {$log[2]} | $message |
";
}
$rows = implode("\n", $rows);
return <<Log Messages
Time |
Level |
Category |
Message |
$rows
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 array(
'messages' => $messages,
);
}
}