Fix issue #73 : ajout d'une page pour visualiser les logs

This commit is contained in:
Marien Fressinaud
2013-06-15 16:42:50 +02:00
parent 1863153b96
commit fafddf2a20
11 changed files with 194 additions and 3 deletions

View File

@@ -36,6 +36,7 @@ class App_FrontController extends FrontController {
include (APP_PATH . '/models/Entry.php');
include (APP_PATH . '/models/EntriesGetter.php');
include (APP_PATH . '/models/RSSPaginator.php');
include (APP_PATH . '/models/Log.php');
}
private function loadParamsView () {

View File

@@ -139,6 +139,32 @@ class indexController extends ActionController {
View::prependTitle (Translate::t ('about') . ' - ');
}
public function logsAction () {
if (login_is_conf ($this->view->conf) && !is_logged ()) {
Error::error (
403,
array ('error' => array (Translate::t ('access_denied')))
);
}
View::prependTitle (Translate::t ('see_logs') . ' - ');
$logs = array();
try {
$logDAO = new LogDAO ();
$logs = $logDAO->lister ();
$logs = array_reverse ($logs);
} catch(FileNotExistException $e) {
}
//gestion pagination
$page = Request::param ('page', 1);
$this->view->logsPaginator = new Paginator ($logs);
$this->view->logsPaginator->_nbItemsPerPage (50);
$this->view->logsPaginator->_currentPage ($page);
}
public function loginAction () {
$this->view->_useLayout (false);

View File

@@ -186,6 +186,9 @@ return array (
'credits' => 'Credits',
'credits_content' => 'Some design elements come from <a href="http://twitter.github.io/bootstrap/">Bootstrap</a> although FreshRSS doesn\'t use this framework. <a href="https://git.gnome.org/browse/gnome-icon-theme-symbolic">Icons</a> come from <a href="https://www.gnome.org/">GNOME project</a>. <em>Open Sans</em> font police used has been created by <a href="https://www.google.com/webfonts/specimen/Open+Sans">Steve Matteson</a>. Favicons are collected with <a href="https://getfavicon.appspot.com/">getFavicon API</a>. FreshRSS is based on <a href="https://github.com/marienfressinaud/MINZ">Minz</a>, a PHP framework.',
'logs' => 'Logs',
'logs_empty' => 'Log file is empty',
// DATE
'january' => 'january',
'february' => 'february',

View File

@@ -186,6 +186,9 @@ return array (
'credits' => 'Crédits',
'credits_content' => 'Des éléments de design sont issus du <a href="http://twitter.github.io/bootstrap/">projet Bootstrap</a> bien que FreshRSS n\'utilise pas ce framework. Les <a href="https://git.gnome.org/browse/gnome-icon-theme-symbolic">icônes</a> sont issues du <a href="https://www.gnome.org/">projet GNOME</a>. La police <em>Open Sans</em> utilisée a été créée par <a href="https://www.google.com/webfonts/specimen/Open+Sans">Steve Matteson</a>. Les favicons sont récupérés grâce au site <a href="https://getfavicon.appspot.com/">getFavicon</a>. FreshRSS repose sur <a href="https://github.com/marienfressinaud/MINZ">Minz</a>, un framework PHP.',
'logs' => 'Logs',
'logs_empty' => 'Les logs sont vides',
// DATE
'january' => 'janvier',
'february' => 'février',

View File

@@ -54,6 +54,7 @@
<li class="item"><a href="<?php echo _url ('configure', 'shortcut'); ?>"><?php echo Translate::t ('shortcuts'); ?></a></li>
<li class="separator"></li>
<li class="item"><a href="<?php echo _url ('index', 'about'); ?>"><?php echo Translate::t ('about'); ?></a></li>
<li class="item"><a href="<?php echo _url ('index', 'logs'); ?>"><?php echo Translate::t ('logs'); ?></a></li>
</ul>
</div>
</div>

47
app/models/Log.php Normal file
View File

@@ -0,0 +1,47 @@
<?php
class Log_Model extends Model {
private $date;
private $level;
private $information;
public function date () {
return $this->date;
}
public function level () {
return $this->level;
}
public function info () {
return $this->information;
}
public function _date ($date) {
$this->date = $date;
}
public function _level ($level) {
$this->level = $level;
}
public function _info ($information) {
$this->information = $information;
}
}
class LogDAO extends Model_txt {
public function __construct () {
parent::__construct (LOG_PATH . '/application.log', 'r+');
}
public function lister () {
$logs = array ();
$i = 0;
while (($line = $this->readLine ()) !== false) {
$logs[$i] = new Log_Model ();
$logs[$i]->_date (preg_replace ("'\[(.*?)\] \[(.*?)\] --- (.*?)'U", "\\1", $line));
$logs[$i]->_level (preg_replace ("'\[(.*?)\] \[(.*?)\] --- (.*?)'U", "\\2", $line));
$logs[$i]->_info (preg_replace ("'\[(.*?)\] \[(.*?)\] --- (.*?)'U", "\\3", $line));
$i++;
}
return $logs;
}
}

View File

@@ -0,0 +1,47 @@
<?php
$c = Request::controllerName ();
$a = Request::actionName ();
$params = Request::params ();
?>
<?php if ($this->nbPage > 1) { ?>
<ul class="pagination">
<?php $params[$getteur] = 1; ?>
<li class="item pager-first">
<?php if ($this->currentPage > 1) { ?>
<a href="<?php echo Url::display (array ('c' => $c, 'a' => $a, 'params' => $params)); ?>">« Début</a>
<?php } ?>
</li>
<?php $params[$getteur] = $this->currentPage - 1; ?>
<li class="item pager-previous">
<?php if ($this->currentPage > 1) { ?>
<a href="<?php echo Url::display (array ('c' => $c, 'a' => $a, 'params' => $params)); ?>"> Précédent</a>
<?php } ?>
</li>
<?php for ($i = $this->currentPage - 2; $i <= $this->currentPage + 2; $i++) { ?>
<?php if($i > 0 && $i <= $this->nbPage) { ?>
<?php if ($i != $this->currentPage) { ?>
<?php $params[$getteur] = $i; ?>
<li class="item pager-item"><a href="<?php echo Url::display (array ('c' => $c, 'a' => $a, 'params' => $params)); ?>"><?php echo $i; ?></a></li>
<?php } else { ?>
<li class="item pager-current"><?php echo $i; ?></li>
<?php } ?>
<?php } ?>
<?php } ?>
<?php $params[$getteur] = $this->currentPage + 1; ?>
<li class="item pager-next">
<?php if ($this->currentPage < $this->nbPage) { ?>
<a href="<?php echo Url::display (array ('c' => $c, 'a' => $a, 'params' => $params)); ?>">Suivant </a>
<?php } ?>
</li>
<?php $params[$getteur] = $this->nbPage; ?>
<li class="item pager-last">
<?php if ($this->currentPage < $this->nbPage) { ?>
<a href="<?php echo Url::display (array ('c' => $c, 'a' => $a, 'params' => $params)); ?>">Fin »</a>
<?php } ?>
</li>
</ul>
<?php } ?>

View File

@@ -0,0 +1,21 @@
<div class="post content">
<a href="<?php echo _url ('index', 'index'); ?>"><?php echo Translate::t ('back_to_rss_feeds'); ?></a>
<h1><?php echo Translate::t ('logs'); ?></h1>
<?php $items = $this->logsPaginator->items (); ?>
<?php if (!empty ($items)) { ?>
<div class="logs">
<?php $this->logsPaginator->render ('logs_pagination.phtml', 'page'); ?>
<?php foreach ($items as $log) { ?>
<div class="log <?php echo $log->level (); ?>"><span class="date"><?php echo date ('d/m/Y - H:i:s', strtotime ($log->date ())); ?></span><?php echo $log->info (); ?></div>
<?php } ?>
<?php $this->logsPaginator->render ('logs_pagination.phtml','page'); ?>
</div>
<?php } else { ?>
<p class="alert alert-warn"><?php echo Translate::t ('logs_empty'); ?></p>
<?php } ?>
</div>

View File

@@ -71,7 +71,7 @@ class View {
} else {
Log::record ('File doesn\'t exist : `'
. $this->view_filename . '`',
Log::WARNING);
Log::NOTICE);
}
}

View File

@@ -27,7 +27,7 @@ class Model_txt {
*/
public function __construct ($nameFile, $mode = 'a+') {
$this->filename = $nameFile;
$this->file = fopen ($this->filename, $mode);
$this->file = @fopen ($this->filename, $mode);
if (!$this->file) {
throw new FileNotExistException (

View File

@@ -349,14 +349,29 @@
}
.pagination .item {
display: table-cell;
border-top: 1px solid #aaa;
line-height: 40px;
}
.pagination .item.pager-current {
font-weight: bold;
font-size: 140%;
}
.pagination .item.pager-first,
.pagination .item.pager-previous,
.pagination .item.pager-next,
.pagination .item.pager-last {
width: 100px;
}
.pagination .item a {
display: block;
color: #333;
font-style: italic;
}
.pagination:first-child .item {
border-bottom: 1px solid #aaa;
}
.pagination:last-child .item {
border-top: 1px solid #aaa;
}
.loading {
background: url("loader.gif") center center no-repeat;
font-size: 0;
@@ -421,6 +436,33 @@
vertical-align: middle;
}
.logs {
border: 1px solid #aaa;
}
.logs .log {
padding: 5px 2%;
overflow: auto;
background: #fafafa;
border-bottom: 1px solid #999;
color: #333;
font-size: 90%;
}
.logs .log .date {
display: block;
}
.logs .log.error {
background: #fdd;
color: #844;
}
.logs .log.warning {
background: #ffe;
color: #c95;
}
.logs .log.notice {
background: #f4f4f4;
color: #aaa;
}
@media(max-width: 840px) {
.header,
.aside .btn-important,