mirror of
https://github.com/yiisoft/yii2.git
synced 2025-08-26 06:15:19 +08:00
Debug toolbar WIP
This commit is contained in:
@ -9,6 +9,8 @@ namespace yii\debug\panels;
|
||||
|
||||
use Yii;
|
||||
use yii\debug\Panel;
|
||||
use yii\helpers\Html;
|
||||
use yii\log\Logger;
|
||||
|
||||
/**
|
||||
* @author Qiang Xue <qiang.xue@gmail.com>
|
||||
@ -33,7 +35,29 @@ EOD;
|
||||
|
||||
public function getDetail()
|
||||
{
|
||||
return '<h2>Logs</h2>';
|
||||
$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]));
|
||||
$rows[] = "<tr><td style=\"width: 100px;\">$time</td><td style=\"width: 100px;\">$level</td><td style=\"width: 250px;\">{$log[2]}</td><td>$message</td></tr>";
|
||||
}
|
||||
$rows = implode("\n", $rows);
|
||||
return <<<EOD
|
||||
<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;
|
||||
}
|
||||
|
||||
public function save()
|
||||
|
@ -65,10 +65,18 @@ EOD;
|
||||
{
|
||||
$rows = array();
|
||||
foreach ($values as $name => $value) {
|
||||
$rows[] = '<tr><th>' . Html::encode($name) . '</th><td>' . Html::encode(var_export($value, true)) . '</td></tr>';
|
||||
$rows[] = '<tr><th style="width: 200px;">' . Html::encode($name) . '</th><td><div style="overflow:auto">' . Html::encode(var_export($value, true)) . '</div></td></tr>';
|
||||
}
|
||||
if (!empty($rows)) {
|
||||
return "<table class=\"table table-condensed table-bordered table-hover\">\n<thead>\n<tr><th>Name</th><th>Value</th></tr>\n</thead>\n<tbody>\n" . implode("\n", $rows) . "\n</tbody>\n</table>";
|
||||
$rows = implode("\n", $rows);
|
||||
return <<<EOD
|
||||
<table class="table table-condensed table-bordered table-striped table-hover" style="table-layout: fixed;">
|
||||
<thead><tr><th style="width: 200px;">Name</th><th>Value</th></tr></thead>
|
||||
<tbody>
|
||||
$rows
|
||||
</tbody>
|
||||
</table>
|
||||
EOD;
|
||||
} else {
|
||||
return 'Empty.';
|
||||
}
|
||||
|
@ -24,6 +24,9 @@ class StringHelper
|
||||
*/
|
||||
public static function strlen($string)
|
||||
{
|
||||
if (!function_exists('mb_strlen')) {
|
||||
throw new \Exception('here');
|
||||
}
|
||||
return mb_strlen($string, '8bit');
|
||||
}
|
||||
|
||||
|
@ -322,4 +322,22 @@ class Logger extends Component
|
||||
|
||||
return $timings;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the text display of the specified level.
|
||||
* @param integer $level the message level, e.g. [[LEVEL_ERROR]], [[LEVEL_WARNING]].
|
||||
* @return string the text display of the level
|
||||
*/
|
||||
public static function getLevelName($level)
|
||||
{
|
||||
static $levels = array(
|
||||
self::LEVEL_ERROR => 'error',
|
||||
self::LEVEL_WARNING => 'warning',
|
||||
self::LEVEL_INFO => 'info',
|
||||
self::LEVEL_TRACE => 'trace',
|
||||
self::LEVEL_PROFILE_BEGIN => 'profile begin',
|
||||
self::LEVEL_PROFILE_END => 'profile end',
|
||||
);
|
||||
return isset($levels[$level]) ? $levels[$level] : 'unknown';
|
||||
}
|
||||
}
|
||||
|
@ -225,16 +225,8 @@ abstract class Target extends Component
|
||||
*/
|
||||
public function formatMessage($message)
|
||||
{
|
||||
static $levels = array(
|
||||
Logger::LEVEL_ERROR => 'error',
|
||||
Logger::LEVEL_WARNING => 'warning',
|
||||
Logger::LEVEL_INFO => 'info',
|
||||
Logger::LEVEL_TRACE => 'trace',
|
||||
Logger::LEVEL_PROFILE_BEGIN => 'profile begin',
|
||||
Logger::LEVEL_PROFILE_END => 'profile end',
|
||||
);
|
||||
list($text, $level, $category, $timestamp) = $message;
|
||||
$level = isset($levels[$level]) ? $levels[$level] : 'unknown';
|
||||
$level = Logger::getLevelName($level);
|
||||
if (!is_string($text)) {
|
||||
$text = var_export($text, true);
|
||||
}
|
||||
|
Reference in New Issue
Block a user