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