Adjust logging configuration to suit the new logger implementation
refs #6038
This commit is contained in:
parent
a5faa8bf25
commit
0b3d3e9bb2
|
@ -31,12 +31,9 @@
|
||||||
namespace Icinga\Form\Config;
|
namespace Icinga\Form\Config;
|
||||||
|
|
||||||
use Zend_Config;
|
use Zend_Config;
|
||||||
use Zend_Form_Element_Text;
|
|
||||||
use Icinga\Application\Config;
|
|
||||||
use Icinga\Application\Icinga;
|
|
||||||
use Icinga\Web\Form;
|
use Icinga\Web\Form;
|
||||||
|
use Icinga\Application\Icinga;
|
||||||
use Icinga\Web\Form\Validator\WritablePathValidator;
|
use Icinga\Web\Form\Validator\WritablePathValidator;
|
||||||
use Icinga\Web\Form\Decorator\ConditionalHidden;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Form class for setting the application wide logging configuration
|
* Form class for setting the application wide logging configuration
|
||||||
|
@ -44,58 +41,13 @@ use Icinga\Web\Form\Decorator\ConditionalHidden;
|
||||||
class LoggingForm extends Form
|
class LoggingForm extends Form
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Base directory to use instead of the one provided by Icinga::app (used for testing)
|
* Return the default logging directory for type "stream"
|
||||||
*
|
*
|
||||||
* @var null
|
* @return string
|
||||||
*/
|
*/
|
||||||
private $baseDir = null;
|
protected function getDefaultLogDir()
|
||||||
|
|
||||||
/**
|
|
||||||
* Set a different base directory to use for default paths instead of the one provided by Icinga::app()
|
|
||||||
*
|
|
||||||
* @param string $dir The new directory to use
|
|
||||||
*/
|
|
||||||
public function setBaseDir($dir)
|
|
||||||
{
|
{
|
||||||
$this->baseDir = $dir;
|
return realpath(Icinga::app()->getApplicationDir() . '/../var/log/icingaweb.log');
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return the applications base directory or the value from a previous setBaseDir call
|
|
||||||
*
|
|
||||||
* This is used to determine the default logging paths in a manner that allows to set a different path
|
|
||||||
* during testing
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getBaseDir()
|
|
||||||
{
|
|
||||||
if ($this->baseDir) {
|
|
||||||
return $this->baseDir;
|
|
||||||
}
|
|
||||||
return realpath(Icinga::app()->getApplicationDir() . '/../');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return true if the debug log path textfield should be displayed
|
|
||||||
*
|
|
||||||
* This is the case if the "logging_use_debug" field is autosubmitted
|
|
||||||
* and true or if it is not submitted, but the configuration for debug
|
|
||||||
* logging is set to true
|
|
||||||
*
|
|
||||||
* @param Zend_Config $config The debug section of the config.ini
|
|
||||||
*
|
|
||||||
* @return bool Whether to display the debug path field or not
|
|
||||||
*/
|
|
||||||
private function shouldDisplayDebugLog(Zend_Config $config)
|
|
||||||
{
|
|
||||||
$debugParam = $this->getRequest()->getParam('logging_debug_enable', null);
|
|
||||||
if ($debugParam !== null) {
|
|
||||||
return intval($debugParam) === 1;
|
|
||||||
} else {
|
|
||||||
return intval($config->get('enable', 0)) === 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -108,108 +60,121 @@ class LoggingForm extends Form
|
||||||
$this->setName('form_config_logging');
|
$this->setName('form_config_logging');
|
||||||
|
|
||||||
$config = $this->getConfiguration();
|
$config = $this->getConfiguration();
|
||||||
$logging = $config->logging;
|
if (($loggingConfig = $config->logging) === null) {
|
||||||
|
$loggingConfig = new Zend_Config(array());
|
||||||
if ($logging === null) {
|
|
||||||
$logging = new Zend_Config(array());
|
|
||||||
}
|
|
||||||
$debug = $logging->debug;
|
|
||||||
if ($debug === null) {
|
|
||||||
$debug = new Zend_Config(array());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$txtLogPath = new Zend_Form_Element_Text(
|
$this->addElement(
|
||||||
|
'checkbox',
|
||||||
|
'logging_enable',
|
||||||
|
array(
|
||||||
|
'required' => true,
|
||||||
|
'label' => t('Logging Enabled'),
|
||||||
|
'helptext' => t('Check this to enable logging.'),
|
||||||
|
'value' => $loggingConfig->enable ? 1 : 0
|
||||||
|
)
|
||||||
|
);
|
||||||
|
$this->addElement(
|
||||||
|
'select',
|
||||||
|
'logging_level',
|
||||||
array(
|
array(
|
||||||
'name' => 'logging_app_target',
|
|
||||||
'label' => 'Application Log Path',
|
|
||||||
'helptext' => 'The logfile to write the icingaweb debug logs to.'
|
|
||||||
. 'The webserver must be able to write at this location',
|
|
||||||
'required' => true,
|
'required' => true,
|
||||||
'value' => $logging->get('target', $this->getBaseDir() . '/var/log/icingaweb.log')
|
'label' => t('Logging Level'),
|
||||||
|
'helptext' => t('The maximum loglevel to emit.'),
|
||||||
|
'value' => intval($loggingConfig->get('level', 0)),
|
||||||
|
'multiOptions' => array(
|
||||||
|
0 => t('Error'),
|
||||||
|
1 => t('Warning'),
|
||||||
|
2 => t('Information'),
|
||||||
|
3 => t('Debug')
|
||||||
|
)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
$txtLogPath->addValidator(new WritablePathValidator());
|
|
||||||
$this->addElement($txtLogPath);
|
|
||||||
|
|
||||||
$this->addElement(
|
$this->addElement(
|
||||||
'checkbox',
|
'select',
|
||||||
'logging_app_verbose',
|
'logging_type',
|
||||||
array(
|
array(
|
||||||
'label' => 'Verbose Logging',
|
'required' => true,
|
||||||
'required' => true,
|
'label' => t('Logging Type'),
|
||||||
'helptext' => 'Check to write more verbose output to the icinga log file',
|
'helptext' => t('The type of logging to utilize.'),
|
||||||
'value' => intval($logging->get('verbose', 0)) === 1
|
'value' => $loggingConfig->get('type', 'stream'),
|
||||||
|
'multiOptions' => array(
|
||||||
|
'stream' => t('File'),
|
||||||
|
'syslog' => 'Syslog'
|
||||||
|
)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
$this->enableAutoSubmit(array('logging_type'));
|
||||||
|
|
||||||
$this->addElement(
|
switch ($this->getRequest()->getParam('logging_type', $loggingConfig->get('type', 'stream')))
|
||||||
'checkbox',
|
{
|
||||||
'logging_debug_enable',
|
case 'stream':
|
||||||
array(
|
$this->addElement(
|
||||||
'label' => 'Use Debug Log',
|
'text',
|
||||||
'required' => true,
|
'logging_target',
|
||||||
'helptext' => 'Check to write a seperate debug log (Warning: This file can grow very big)',
|
array(
|
||||||
'value' => $this->shouldDisplayDebugLog($debug)
|
'required' => true,
|
||||||
)
|
'label' => t('Filepath'),
|
||||||
);
|
'helptext' => t('The logfile to write messages to.'),
|
||||||
|
'value' => $loggingConfig->target ? $loggingConfig->target : $this->getDefaultLogDir(),
|
||||||
|
'validators' => array(new WritablePathValidator())
|
||||||
|
)
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
case 'syslog':
|
||||||
|
$this->addElement(
|
||||||
|
'text',
|
||||||
|
'logging_application',
|
||||||
|
array(
|
||||||
|
'required' => true,
|
||||||
|
'label' => t('Application Prefix'),
|
||||||
|
'helptext' => t('The name of the application by which to prefix syslog messages.'),
|
||||||
|
'value' => $loggingConfig->get('application', 'icingaweb')
|
||||||
|
)
|
||||||
|
);
|
||||||
|
$this->addElement(
|
||||||
|
'select',
|
||||||
|
'logging_facility',
|
||||||
|
array(
|
||||||
|
'required' => true,
|
||||||
|
'label' => t('Facility'),
|
||||||
|
'helptext' => t('The Syslog facility to utilize.'),
|
||||||
|
'value' => $loggingConfig->get('facility', 'LOG_USER'),
|
||||||
|
'multiOptions' => array(
|
||||||
|
'LOG_USER'
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
$textLoggingDebugPath = new Zend_Form_Element_Text(
|
$this->setSubmitLabel('{{SAVE_ICON}} Save Changes');
|
||||||
array(
|
|
||||||
'name' => 'logging_debug_target',
|
|
||||||
'label' => 'Debug Log Path',
|
|
||||||
'required' => $this->shouldDisplayDebugLog($debug),
|
|
||||||
'condition' => $this->shouldDisplayDebugLog($debug),
|
|
||||||
'value' => $debug->get('target', $this->getBaseDir() . '/var/log/icingaweb2.debug.log'),
|
|
||||||
'helptext' => 'Set the path to the debug log'
|
|
||||||
)
|
|
||||||
);
|
|
||||||
$textLoggingDebugPath->addValidator(new WritablePathValidator());
|
|
||||||
|
|
||||||
$decorator = new ConditionalHidden();
|
|
||||||
$this->addElement($textLoggingDebugPath);
|
|
||||||
$textLoggingDebugPath->addDecorator($decorator);
|
|
||||||
|
|
||||||
$this->enableAutoSubmit(array('logging_debug_enable'));
|
|
||||||
|
|
||||||
$this->addElement(
|
|
||||||
'button',
|
|
||||||
'btn_submit',
|
|
||||||
array(
|
|
||||||
'type' => 'submit',
|
|
||||||
'escape' => false,
|
|
||||||
'value' => '1',
|
|
||||||
'class' => 'btn btn-cta btn-common',
|
|
||||||
'label' => '<i class="icinga-icon-save"></i> Save Changes'
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return a Zend_Config object containing the state defined in this form
|
* Return a Zend_Config object containing the state defined in this form
|
||||||
*
|
*
|
||||||
* @return Zend_Config The config defined in this form
|
* @return Zend_Config The config defined in this form
|
||||||
*/
|
*/
|
||||||
public function getConfig()
|
public function getConfig()
|
||||||
{
|
{
|
||||||
$config = $this->getConfiguration();
|
|
||||||
if ($config->logging === null) {
|
|
||||||
$config->logging = new Zend_Config(array(), true);
|
|
||||||
}
|
|
||||||
if ($config->logging->debug === null) {
|
|
||||||
$config->logging->debug = new Zend_Config(array(), true);
|
|
||||||
}
|
|
||||||
|
|
||||||
$values = $this->getValues();
|
$values = $this->getValues();
|
||||||
$cfg = $config->toArray();
|
$cfg = $this->getConfiguration()->toArray();
|
||||||
|
|
||||||
$cfg['logging']['enable'] = 1;
|
$cfg['logging']['enable'] = $values['logging_enable'] == 1;
|
||||||
$cfg['logging']['type'] = 'stream';
|
$cfg['logging']['level'] = $values['logging_level'];
|
||||||
$cfg['logging']['verbose'] = $values['logging_app_verbose'];
|
|
||||||
$cfg['logging']['target'] = $values['logging_app_target'];
|
switch ($values['logging_type'])
|
||||||
|
{
|
||||||
|
case 'stream':
|
||||||
|
$cfg['logging']['target'] = $values['logging_target'];
|
||||||
|
break;
|
||||||
|
case 'syslog':
|
||||||
|
$cfg['logging']['application'] = $values['logging_application'];
|
||||||
|
$cfg['logging']['facility'] = $values['logging_facility'];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
$cfg['logging']['debug']['enable'] = intval($values['logging_debug_enable']);
|
|
||||||
$cfg['logging']['debug']['type'] = 'stream';
|
|
||||||
$cfg['logging']['debug']['target'] = $values['logging_debug_target'];
|
|
||||||
return new Zend_Config($cfg);
|
return new Zend_Config($cfg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue