Commit db16f754 authored by xjm's avatar xjm

Issue #1748410 by wesleydv, c.nish2k3, dasha_v, Thomasdbcklr, John Cook,...

Issue #1748410 by wesleydv, c.nish2k3, dasha_v, Thomasdbcklr, John Cook, dagmar, sgarrahy, falc0, doublejosh, alexpott: Include !severity in logged events by syslog
parent f0a96990
......@@ -77,6 +77,7 @@ public function log($level, $message, array $context = []) {
'!ip' => $context['ip'],
'!request_uri' => $context['request_uri'],
'!referer' => $context['referer'],
'!severity' => $level,
'!uid' => $context['uid'],
'!link' => strip_tags($context['link']),
'!message' => strip_tags($message),
......
......@@ -54,7 +54,7 @@ function syslog_form_system_logging_settings_alter(&$form, FormStateInterface $f
'#type' => 'textarea',
'#title' => t('Syslog format'),
'#default_value' => $config->get('format'),
'#description' => t('Specify the format of the syslog entry. Available variables are: <dl><dt><code>!base_url</code></dt><dd>Base URL of the site.</dd><dt><code>!timestamp</code></dt><dd>Unix timestamp of the log entry.</dd><dt><code>!type</code></dt><dd>The category to which this message belongs.</dd><dt><code>!ip</code></dt><dd>IP address of the user triggering the message.</dd><dt><code>!request_uri</code></dt><dd>The requested URI.</dd><dt><code>!referer</code></dt><dd>HTTP Referer if available.</dd><dt><code>!uid</code></dt><dd>User ID.</dd><dt><code>!link</code></dt><dd>A link to associate with the message.</dd><dt><code>!message</code></dt><dd>The message to store in the log.</dd></dl>'),
'#description' => t('Specify the format of the syslog entry. Available variables are: <dl><dt><code>!base_url</code></dt><dd>Base URL of the site.</dd><dt><code>!timestamp</code></dt><dd>Unix timestamp of the log entry.</dd><dt><code>!type</code></dt><dd>The category to which this message belongs.</dd><dt><code>!ip</code></dt><dd>IP address of the user triggering the message.</dd><dt><code>!request_uri</code></dt><dd>The requested URI.</dd><dt><code>!referer</code></dt><dd>HTTP Referer if available.</dd><dt><code>!severity</code></dt><dd>The severity level of the event; ranges from 0 (Emergency) to 7 (Debug).</dd><dt><code>!uid</code></dt><dd>User ID.</dd><dt><code>!link</code></dt><dd>A link to associate with the message.</dd><dt><code>!message</code></dt><dd>The message to store in the log.</dd></dl>'),
];
$form['#submit'][] = 'syslog_logging_settings_submit';
......
......@@ -4,7 +4,6 @@
use Drupal\KernelTests\KernelTestBase;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
/**
* Test syslog logger functionality.
......@@ -54,4 +53,26 @@ public function testSyslogWriting() {
$this->assertEquals('My warning message.', $log[8]);
}
/**
* Test severity level logging.
*
* @covers ::log
*/
public function testSyslogSeverity() {
/* @var \Drupal\Core\Config\Config $config */
$config = $this->container->get('config.factory')->getEditable('syslog.settings');
$config->set('format', '!type|!message|!severity');
$config->save();
\Drupal::logger('my_module')->warning('My warning message.');
$log_filename = $this->container->get('file_system')->realpath('public://syslog.log');
$logs = explode(PHP_EOL, file_get_contents($log_filename));
$log = explode('|', $logs[0]);
$this->assertEquals('my_module', $log[0]);
$this->assertEquals('My warning message.', $log[1]);
$this->assertEquals('4', $log[2]);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment