Menu: do not show application log when none exists
Added new functions to the logger to get rid of distributed logging config "knowledge". fixes #7062 fixes #7098
This commit is contained in:
parent
975985dc8c
commit
b034028ff8
|
@ -9,6 +9,7 @@ use Icinga\Data\ResourceFactory;
|
|||
use Icinga\Logger\Logger;
|
||||
use Icinga\Logger\Writer\FileWriter;
|
||||
use Icinga\Protocol\File\FileReader;
|
||||
use \Zend_Controller_Action_Exception as ActionError;
|
||||
|
||||
/**
|
||||
* Class ListController
|
||||
|
@ -38,20 +39,21 @@ class ListController extends Controller
|
|||
*/
|
||||
public function applicationlogAction()
|
||||
{
|
||||
if (! Logger::writesToFile()) {
|
||||
throw new ActionError('Site not found', 404);
|
||||
}
|
||||
|
||||
$this->addTitleTab('application log');
|
||||
$pattern = '/^(?<datetime>[0-9]{4}(-[0-9]{2}){2}' // date
|
||||
. 'T[0-9]{2}(:[0-9]{2}){2}([\\+\\-][0-9]{2}:[0-9]{2})?)' // time
|
||||
. ' - (?<loglevel>[A-Za-z]+)' // loglevel
|
||||
. ' - (?<message>.*)$/' // message
|
||||
|
||||
$loggerWriter = Logger::getInstance()->getWriter();
|
||||
if ($loggerWriter instanceof FileWriter) {
|
||||
$resource = new FileReader(new Zend_Config(array(
|
||||
'filename' => $loggerWriter->getPath(),
|
||||
'fields' => '/^(?<datetime>[0-9]{4}(-[0-9]{2}){2}' // date
|
||||
. 'T[0-9]{2}(:[0-9]{2}){2}([\\+\\-][0-9]{2}:[0-9]{2})?)' // time
|
||||
. ' - (?<loglevel>[A-Za-z]+)' // loglevel
|
||||
. ' - (?<message>.*)$/' // message
|
||||
)));
|
||||
$this->view->logData = $resource->select()->order('DESC')->paginate();
|
||||
} else {
|
||||
$this->view->logData = null;
|
||||
}
|
||||
$resource = new FileReader(new Zend_Config(array(
|
||||
'filename' => $loggerWriter->getPath(),
|
||||
'fields' => $pattern
|
||||
)));
|
||||
$this->view->logData = $resource->select()->order('DESC')->paginate();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,6 +27,13 @@ class Logger
|
|||
*/
|
||||
protected $writer;
|
||||
|
||||
/**
|
||||
* The configured type
|
||||
*
|
||||
* @string Type (syslog, file)
|
||||
*/
|
||||
protected $type = 'none';
|
||||
|
||||
/**
|
||||
* The maximum severity to emit
|
||||
*
|
||||
|
@ -83,6 +90,7 @@ class Logger
|
|||
$config->type
|
||||
);
|
||||
}
|
||||
$this->type = $config->type;
|
||||
|
||||
return new $class($config);
|
||||
}
|
||||
|
@ -204,6 +212,16 @@ class Logger
|
|||
return $this->writer;
|
||||
}
|
||||
|
||||
public static function writesToSyslog()
|
||||
{
|
||||
return static::$instance && static::$instance->type === 'syslog';
|
||||
}
|
||||
|
||||
public static function writesToFile()
|
||||
{
|
||||
return static::$instance && static::$instance->type === 'file';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get this' instance
|
||||
*
|
||||
|
|
|
@ -8,6 +8,7 @@ use RecursiveIterator;
|
|||
use Zend_Config;
|
||||
use Icinga\Application\Config;
|
||||
use Icinga\Application\Icinga;
|
||||
use Icinga\Logger\Logger;
|
||||
use Icinga\Exception\ConfigurationError;
|
||||
use Icinga\Exception\ProgrammingError;
|
||||
use Icinga\Web\Url;
|
||||
|
@ -195,10 +196,13 @@ class Menu implements RecursiveIterator
|
|||
'url' => 'config/modules',
|
||||
'priority' => 400
|
||||
));
|
||||
$section->add(t('ApplicationLog'), array(
|
||||
'url' => 'list/applicationlog',
|
||||
'priority' => 500
|
||||
));
|
||||
|
||||
if (Logger::writesToFile()) {
|
||||
$section->add(t('Application Log'), array(
|
||||
'url' => 'list/applicationlog',
|
||||
'priority' => 500
|
||||
));
|
||||
}
|
||||
|
||||
$this->add(t('Logout'), array(
|
||||
'url' => 'authentication/logout',
|
||||
|
|
Loading…
Reference in New Issue