Commit 840a84db by Qiang Xue

debug toolbar refactoring.

parent b6ffa7c9
......@@ -20,12 +20,14 @@ class LogTarget extends Target
* @var Module
*/
public $module;
public $maxLogFiles = 20;
public $tag;
public $historySize = 20;
public function __construct($module, $config = array())
{
parent::__construct($config);
$this->module = $module;
$this->tag = date('Ymd-His', microtime(true));
}
/**
......@@ -38,8 +40,7 @@ class LogTarget extends Target
if (!is_dir($path)) {
mkdir($path);
}
$tag = Yii::$app->getLog()->getTag();
$file = "$path/$tag.log";
$file = "$path/{$this->tag}.log";
$data = array();
foreach ($this->module->panels as $panel) {
$data[$panel->id] = $panel->save();
......@@ -78,8 +79,8 @@ class LogTarget extends Target
}
}
sort($files);
if (count($files) > $this->maxLogFiles) {
$n = count($files) - $this->maxLogFiles;
if (count($files) > $this->historySize) {
$n = count($files) - $this->historySize;
foreach ($files as $i => $file) {
if ($i < $n) {
unlink($file);
......
......@@ -63,8 +63,9 @@ class Module extends \yii\base\Module
{
/** @var View $view */
$id = 'yii-debug-toolbar';
$tag = Yii::$app->getLog()->targets['debug']->tag;
$url = Yii::$app->getUrlManager()->createUrl('debug/default/toolbar', array(
'tag' => Yii::$app->getLog()->getTag(),
'tag' => $tag,
));
$view = $event->sender;
$view->registerJs("yii.debug.load('$id', '$url');");
......
......@@ -40,6 +40,7 @@ class DefaultController extends Controller
{
$this->loadData($tag);
return $this->renderPartial('toolbar', array(
'tag' => $tag,
'panels' => $this->module->panels,
));
}
......
......@@ -24,12 +24,10 @@ class ConfigPanel extends Panel
public function getSummary()
{
$link = Html::a('more details', array('index', 'tag' => $this->data['tag']));
return <<<EOD
<div class="yii-debug-toolbar-block">
PHP: {$this->data['phpVersion']},
Yii: {$this->data['phpVersion']},
$link
Yii: {$this->data['phpVersion']}
</div>
EOD;
}
......@@ -42,7 +40,6 @@ EOD;
public function save()
{
return array(
'tag' => Yii::$app->getLog()->getTag(),
'phpVersion' => PHP_VERSION,
'yiiVersion' => Yii::getVersion(),
);
......
......@@ -2,7 +2,9 @@
/**
* @var \yii\base\View $this
* @var \yii\debug\Panel[] $panels
* @var string $tag
*/
use yii\helpers\Html;
?>
<style>
#yii-debug-toolbar {
......@@ -28,4 +30,7 @@
<?php foreach ($panels as $panel): ?>
<?php echo $panel->getSummary(); ?>
<?php endforeach; ?>
<div class="yii-debug-toolbar-block">
<?php echo Html::a('more details', array('index', 'tag' => $tag)); ?>
</div>
</div>
......@@ -129,13 +129,6 @@ class Logger extends Component
*/
public $targets = array();
/**
* @var string
*/
private $_tag;
/**
* Initializes the logger by registering [[flush()]] as a shutdown function.
*/
......@@ -197,25 +190,6 @@ class Logger extends Component
}
/**
* @return string a tag that uniquely identifies the current request.
*/
public function getTag()
{
if ($this->_tag === null) {
$this->_tag = date('Ymd-His', microtime(true));
}
return $this->_tag;
}
/**
* @param string $tag a tag that uniquely identifies the current request.
*/
public function setTag($tag)
{
$this->_tag = $tag;
}
/**
* Returns the total elapsed time since the start of the current request.
* This method calculates the difference between now and the timestamp
* defined by constant `YII_BEGIN_TIME` which is evaluated at the beginning
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment