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.
106 lines
2.9 KiB
106 lines
2.9 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
|
|
||
|
/**
|
||
12 years ago
|
* Debugger panel that collects and displays logs.
|
||
|
*
|
||
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()
|
||
|
{
|
||
11 years ago
|
$output = ['<span class="label">' . count($this->data['messages']) . '</span>'];
|
||
12 years ago
|
$title = 'Logged ' . count($this->data['messages']) . ' messages';
|
||
12 years ago
|
$errorCount = count(Target::filterMessages($this->data['messages'], Logger::LEVEL_ERROR));
|
||
12 years ago
|
if ($errorCount) {
|
||
12 years ago
|
$output[] = '<span class="label label-important">' . $errorCount . '</span>';
|
||
|
$title .= ", $errorCount errors";
|
||
12 years ago
|
}
|
||
|
$warningCount = count(Target::filterMessages($this->data['messages'], Logger::LEVEL_WARNING));
|
||
12 years ago
|
if ($warningCount) {
|
||
12 years ago
|
$output[] = '<span class="label label-warning">' . $warningCount . '</span>';
|
||
|
$title .= ", $warningCount warnings";
|
||
12 years ago
|
}
|
||
12 years ago
|
$log = implode(' ', $output);
|
||
|
$url = $this->getUrl();
|
||
|
return <<<EOD
|
||
12 years ago
|
<div class="yii-debug-toolbar-block">
|
||
12 years ago
|
<a href="$url" title="$title">Log $log</a>
|
||
12 years ago
|
</div>
|
||
|
EOD;
|
||
|
}
|
||
|
|
||
|
public function getDetail()
|
||
|
{
|
||
11 years ago
|
$rows = [];
|
||
12 years ago
|
foreach ($this->data['messages'] as $log) {
|
||
12 years ago
|
list ($message, $level, $category, $time, $traces) = $log;
|
||
|
$time = date('H:i:s.', $time) . sprintf('%03d', (int)(($time - (int)$time) * 1000));
|
||
12 years ago
|
$message = nl2br(Html::encode($message));
|
||
12 years ago
|
if (!empty($traces)) {
|
||
11 years ago
|
$message .= Html::ul($traces, [
|
||
12 years ago
|
'class' => 'trace',
|
||
|
'item' => function ($trace) {
|
||
|
return "<li>{$trace['file']}({$trace['line']})</li>";
|
||
|
},
|
||
11 years ago
|
]);
|
||
12 years ago
|
}
|
||
|
if ($level == Logger::LEVEL_ERROR) {
|
||
12 years ago
|
$class = ' class="danger"';
|
||
12 years ago
|
} elseif ($level == Logger::LEVEL_WARNING) {
|
||
12 years ago
|
$class = ' class="warning"';
|
||
12 years ago
|
} elseif ($level == Logger::LEVEL_INFO) {
|
||
12 years ago
|
$class = ' class="success"';
|
||
12 years ago
|
} else {
|
||
|
$class = '';
|
||
|
}
|
||
12 years ago
|
$level = Logger::getLevelName($level);
|
||
12 years ago
|
$rows[] = "<tr$class><td style=\"width: 100px;\">$time</td><td style=\"width: 100px;\">$level</td><td style=\"width: 250px;\">$category</td><td><div>$message</div></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>
|
||
12 years ago
|
<th style="width: 65px;">Level</th>
|
||
12 years ago
|
<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);
|
||
11 years ago
|
return ['messages' => $messages];
|
||
12 years ago
|
}
|
||
|
}
|