Merge branch 'feature/emit-log-messages-in-the-webserver-s-log-11652'

resolves #11652
This commit is contained in:
Alexander A. Klimov 2016-11-04 17:15:06 +01:00
commit f27e8c059d
5 changed files with 67 additions and 4 deletions

View File

@ -39,6 +39,7 @@ class LoggingConfigForm extends Form
'label' => $this->translate('Logging Type'), 'label' => $this->translate('Logging Type'),
'description' => $this->translate('The type of logging to utilize.'), 'description' => $this->translate('The type of logging to utilize.'),
'multiOptions' => array( 'multiOptions' => array(
'php' => $this->translate('Webserver Log', 'app.config.logging.type'),
'syslog' => 'Syslog', 'syslog' => 'Syslog',
'file' => $this->translate('File', 'app.config.logging.type'), 'file' => $this->translate('File', 'app.config.logging.type'),
'none' => $this->translate('None', 'app.config.logging.type') 'none' => $this->translate('None', 'app.config.logging.type')
@ -64,7 +65,7 @@ class LoggingConfigForm extends Form
); );
} }
if (false === isset($formData['logging_log']) || $formData['logging_log'] === 'syslog') { if (false === isset($formData['logging_log']) || in_array($formData['logging_log'], array('syslog', 'php'))) {
$this->addElement( $this->addElement(
'text', 'text',
'logging_application', 'logging_application',
@ -72,7 +73,7 @@ class LoggingConfigForm extends Form
'required' => true, 'required' => true,
'label' => $this->translate('Application Prefix'), 'label' => $this->translate('Application Prefix'),
'description' => $this->translate( 'description' => $this->translate(
'The name of the application by which to prefix syslog messages.' 'The name of the application by which to prefix log messages.'
), ),
'requirement' => $this->translate('The application prefix must not contain whitespace.'), 'requirement' => $this->translate('The application prefix must not contain whitespace.'),
'value' => 'icingaweb2', 'value' => 'icingaweb2',

View File

@ -2979,6 +2979,11 @@ msgctxt "app.config.logging.level"
msgid "Warning" msgid "Warning"
msgstr "Warnung" msgstr "Warnung"
#: /vagrant/application/forms/Config/General/LoggingConfigForm.php:40
msgctxt "app.config.logging.type"
msgid "Webserver Log"
msgstr "Webserver-Log"
#: /vagrant/application/views/scripts/authentication/login.phtml:5 #: /vagrant/application/views/scripts/authentication/login.phtml:5
msgid "" msgid ""
"Welcome to Icinga Web 2. For users of the screen reader Jaws full and " "Welcome to Icinga Web 2. For users of the screen reader Jaws full and "

View File

@ -0,0 +1,45 @@
<?php
/* Icinga Web 2 | (c) 2016 Icinga Development Team | GPLv2+ */
namespace Icinga\Application\Logger\Writer;
use Icinga\Application\Logger;
use Icinga\Application\Logger\LogWriter;
use Icinga\Data\ConfigObject;
use Icinga\Exception\NotWritableError;
/**
* Log to the webserver log, a file or syslog
*
* @see https://secure.php.net/manual/en/errorfunc.configuration.php#ini.error-log
*/
class PhpWriter extends LogWriter
{
/**
* Prefix to prepend to each message
*
* @var string
*/
protected $ident;
/**
* {@inheritDoc}
*/
public function __construct(ConfigObject $config)
{
parent::__construct($config);
$this->ident = $config->get('application', 'icingaweb2');
}
/**
* {@inheritdoc}
*/
public function log($severity, $message)
{
if (! error_log($this->ident . ': ' . Logger::$levels[$severity] . ' - ' . (
ini_get('error_log') === 'syslog' ? str_replace("\n", ' ', $message) : $message
))) {
throw new NotWritableError('Could not log to ' . (ini_get('error_log') ?: 'SAPI'));
}
}
}

View File

@ -70,12 +70,24 @@ class GeneralConfigStep extends Step
$loggingHtml = '<p>' . mt('setup', 'Logging will be disabled.') . '</p>'; $loggingHtml = '<p>' . mt('setup', 'Logging will be disabled.') . '</p>';
} else { } else {
$level = $this->data['generalConfig']['logging_level']; $level = $this->data['generalConfig']['logging_level'];
switch ($type) {
case 'syslog':
$typeText = t('Syslog', 'app.config.logging.type');
break;
case 'php':
$typeText = t('Webserver Log', 'app.config.logging.type');
break;
case 'file':
$typeText = t('File', 'app.config.logging.type');
break;
}
$loggingHtml = '' $loggingHtml = ''
. '<table>' . '<table>'
. '<tbody>' . '<tbody>'
. '<tr>' . '<tr>'
. '<td><strong>' . t('Type', 'app.config.logging') . '</strong></td>' . '<td><strong>' . t('Type', 'app.config.logging') . '</strong></td>'
. '<td>' . ($type === 'syslog' ? 'Syslog' : t('File', 'app.config.logging.type')) . '</td>' . '<td>' . $typeText . '</td>'
. '</tr>' . '</tr>'
. '<tr>' . '<tr>'
. '<td><strong>' . t('Level', 'app.config.logging') . '</strong></td>' . '<td><strong>' . t('Level', 'app.config.logging') . '</strong></td>'
@ -88,7 +100,7 @@ class GeneralConfigStep extends Step
)) . '</td>' )) . '</td>'
. '</tr>' . '</tr>'
. '<tr>' . '<tr>'
. ($type === 'syslog' ? ( . ($type !== 'file' ? (
'<td><strong>' . t('Application Prefix') . '</strong></td>' '<td><strong>' . t('Application Prefix') . '</strong></td>'
. '<td>' . $this->data['generalConfig']['logging_application'] . '</td>' . '<td>' . $this->data['generalConfig']['logging_application'] . '</td>'
) : ( ) : (