Commit 14507bf6 by Qiang Xue

minor issue fixes.

parent 7a4572fd
...@@ -57,6 +57,7 @@ class LogTarget extends Target ...@@ -57,6 +57,7 @@ class LogTarget extends Target
'ip' => $request->getUserIP(), 'ip' => $request->getUserIP(),
'time' => time(), 'time' => time(),
); );
$this->gc($manifest);
$dataFile = "$path/{$this->tag}.json"; $dataFile = "$path/{$this->tag}.json";
$data = array(); $data = array();
...@@ -82,4 +83,19 @@ class LogTarget extends Target ...@@ -82,4 +83,19 @@ class LogTarget extends Target
$this->export($this->messages); $this->export($this->messages);
} }
} }
protected function gc(&$manifest)
{
if (rand(0, 100) < 5 && count($manifest) > $this->module->historySize) {
$n = count($manifest) - $this->module->historySize;
foreach (array_keys($manifest) as $tag) {
$file = $this->module->dataPath . "/$tag.json";
@unlink($file);
unset($manifest[$tag]);
if (--$n <= 0) {
break;
}
}
}
}
} }
...@@ -29,11 +29,11 @@ class LogPanel extends Panel ...@@ -29,11 +29,11 @@ class LogPanel extends Panel
$output = array(); $output = array();
$errorCount = count(Target::filterMessages($this->data['messages'], Logger::LEVEL_ERROR)); $errorCount = count(Target::filterMessages($this->data['messages'], Logger::LEVEL_ERROR));
if ($errorCount) { if ($errorCount) {
$output[] = '<span class="label label-important">$errorCount</span> ' . ($errorCount > 1 ? 'errors' : 'error'); $output[] = '<span class="label label-important">' . $errorCount . '</span> ' . ($errorCount > 1 ? 'errors' : 'error');
} }
$warningCount = count(Target::filterMessages($this->data['messages'], Logger::LEVEL_WARNING)); $warningCount = count(Target::filterMessages($this->data['messages'], Logger::LEVEL_WARNING));
if ($warningCount) { if ($warningCount) {
$output[] = '<span class="label label-warning">$warningCount</span> ' . ($warningCount > 1 ? 'warnings' : 'warning'); $output[] = '<span class="label label-warning">' . $warningCount . '</span> ' . ($warningCount > 1 ? 'warnings' : 'warning');
} }
if (!empty($output)) { if (!empty($output)) {
$log = implode(', ', $output); $log = implode(', ', $output);
......
...@@ -107,7 +107,7 @@ EOD; ...@@ -107,7 +107,7 @@ EOD;
'flashes' => $session ? $session->getAllFlashes() : array(), 'flashes' => $session ? $session->getAllFlashes() : array(),
'requestHeaders' => $requestHeaders, 'requestHeaders' => $requestHeaders,
'responseHeaders' => $responseHeaders, 'responseHeaders' => $responseHeaders,
'route' => Yii::$app->requestedAction->getUniqueId(), 'route' => Yii::$app->requestedAction ? Yii::$app->requestedAction->getUniqueId() : Yii::$app->requestedRoute,
'action' => $action, 'action' => $action,
'actionParams' => Yii::$app->requestedParams, 'actionParams' => Yii::$app->requestedParams,
'SERVER' => empty($_SERVER) ? array() : $_SERVER, 'SERVER' => empty($_SERVER) ? array() : $_SERVER,
......
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