Merge branch 'feature/allow-to-configure-the-syslog-facility-11214'
resolves #11214
This commit is contained in:
commit
418a428f1e
|
@ -4,6 +4,8 @@
|
||||||
namespace Icinga\Forms\Config\General;
|
namespace Icinga\Forms\Config\General;
|
||||||
|
|
||||||
use Icinga\Application\Logger;
|
use Icinga\Application\Logger;
|
||||||
|
use Icinga\Application\Logger\Writer\SyslogWriter;
|
||||||
|
use Icinga\Application\Platform;
|
||||||
use Icinga\Web\Form;
|
use Icinga\Web\Form;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -90,22 +92,31 @@ class LoggingConfigForm extends Form
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
/*
|
|
||||||
* Note(el): Since we provide only one possible value for the syslog facility, I opt against exposing
|
if (Platform::isWindows()) {
|
||||||
* this configuration.
|
/* @see https://secure.php.net/manual/en/function.openlog.php */
|
||||||
*/
|
$this->addElement(
|
||||||
// $this->addElement(
|
'hidden',
|
||||||
// 'select',
|
'logging_facility',
|
||||||
// 'logging_facility',
|
array(
|
||||||
// array(
|
'value' => 'user',
|
||||||
// 'required' => true,
|
'disabled' => true
|
||||||
// 'label' => $this->translate('Facility'),
|
)
|
||||||
// 'description' => $this->translate('The syslog facility to utilize.'),
|
);
|
||||||
// 'multiOptions' => array(
|
} else {
|
||||||
// 'user' => 'LOG_USER'
|
$facilities = array_keys(SyslogWriter::$facilities);
|
||||||
// )
|
$this->addElement(
|
||||||
// )
|
'select',
|
||||||
// );
|
'logging_facility',
|
||||||
|
array(
|
||||||
|
'required' => true,
|
||||||
|
'label' => $this->translate('Facility'),
|
||||||
|
'description' => $this->translate('The syslog facility to utilize.'),
|
||||||
|
'value' => 'user',
|
||||||
|
'multiOptions' => array_combine($facilities, $facilities)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
} elseif (isset($formData['logging_log']) && $formData['logging_log'] === 'file') {
|
} elseif (isset($formData['logging_log']) && $formData['logging_log'] === 'file') {
|
||||||
$this->addElement(
|
$this->addElement(
|
||||||
'text',
|
'text',
|
||||||
|
|
|
@ -6,6 +6,7 @@ namespace Icinga\Application\Logger\Writer;
|
||||||
use Icinga\Data\ConfigObject;
|
use Icinga\Data\ConfigObject;
|
||||||
use Icinga\Application\Logger;
|
use Icinga\Application\Logger;
|
||||||
use Icinga\Application\Logger\LogWriter;
|
use Icinga\Application\Logger\LogWriter;
|
||||||
|
use Icinga\Exception\ConfigurationError;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Log to the syslog service
|
* Log to the syslog service
|
||||||
|
@ -32,7 +33,15 @@ class SyslogWriter extends LogWriter
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
public static $facilities = array(
|
public static $facilities = array(
|
||||||
'user' => LOG_USER
|
'user' => LOG_USER,
|
||||||
|
'local0' => LOG_LOCAL0,
|
||||||
|
'local1' => LOG_LOCAL1,
|
||||||
|
'local2' => LOG_LOCAL2,
|
||||||
|
'local3' => LOG_LOCAL3,
|
||||||
|
'local4' => LOG_LOCAL4,
|
||||||
|
'local5' => LOG_LOCAL5,
|
||||||
|
'local6' => LOG_LOCAL6,
|
||||||
|
'local7' => LOG_LOCAL7
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -55,7 +64,16 @@ class SyslogWriter extends LogWriter
|
||||||
public function __construct(ConfigObject $config)
|
public function __construct(ConfigObject $config)
|
||||||
{
|
{
|
||||||
$this->ident = $config->get('application', 'icingaweb2');
|
$this->ident = $config->get('application', 'icingaweb2');
|
||||||
$this->facility = static::$facilities['user'];
|
|
||||||
|
$configuredFacility = $config->get('facility', 'user');
|
||||||
|
if (! isset(static::$facilities[$configuredFacility])) {
|
||||||
|
throw new ConfigurationError(
|
||||||
|
'Invalid logging facility: "%s" (expected one of: %s)',
|
||||||
|
$configuredFacility,
|
||||||
|
implode(', ', array_keys(static::$facilities))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
$this->facility = static::$facilities[$configuredFacility];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue