Yii2 Bootstrap 3
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

97 lines
2.4 KiB

12 years ago
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace yii\debug\panels;
use Yii;
use yii\debug\Panel;
12 years ago
use yii\helpers\Html;
use yii\log\Logger;
12 years ago
use yii\log\Target;
12 years ago
/**
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*/
class LogPanel extends Panel
{
public function getName()
{
return 'Logs';
}
public function getSummary()
{
12 years ago
$output = array();
$errorCount = count(Target::filterMessages($this->data['messages'], Logger::LEVEL_ERROR));
if ($errorCount) {
$output[] = '<span class="label label-important">$errorCount</span> ' . ($errorCount > 1 ? 'errors' : 'error');
12 years ago
}
$warningCount = count(Target::filterMessages($this->data['messages'], Logger::LEVEL_WARNING));
if ($warningCount) {
$output[] = '<span class="label label-warning">$warningCount</span> ' . ($warningCount > 1 ? 'warnings' : 'warning');
12 years ago
}
if (!empty($output)) {
$log = implode(', ', $output);
return <<<EOD
12 years ago
<div class="yii-debug-toolbar-block">
12 years ago
$log
12 years ago
</div>
EOD;
12 years ago
} else {
return '';
}
12 years ago
}
public function getDetail()
{
12 years ago
$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]));
12 years ago
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[] = "<tr$class><td style=\"width: 100px;\">$time</td><td style=\"width: 100px;\">$level</td><td style=\"width: 250px;\">{$log[2]}</td><td>$message</td></tr>";
12 years ago
}
$rows = implode("\n", $rows);
return <<<EOD
12 years ago
<h1>Log Messages</h1>
12 years ago
<table class="table table-condensed table-bordered table-striped table-hover" style="table-layout: fixed;">
<thead>
<tr>
<th style="width: 100px;">Time</th>
<th style="width: 100px;">Level</th>
<th style="width: 250px;">Category</th>
<th>Message</th>
</tr>
</thead>
<tbody>
$rows
</tbody>
</table>
EOD;
12 years ago
}
public function save()
{
12 years ago
$target = $this->module->logTarget;
$messages = $target->filterMessages($target->messages, Logger::LEVEL_ERROR | Logger::LEVEL_INFO | Logger::LEVEL_WARNING | Logger::LEVEL_TRACE);
12 years ago
return array(
12 years ago
'messages' => $messages,
12 years ago
);
}
}