Skip to content
Snippets Groups Projects
Commit 58a4457b authored by catch's avatar catch
Browse files

Issue #3224414 by alexpott, varshith, dagmar, daffie: Installing the syslog...

Issue #3224414 by alexpott, varshith, dagmar, daffie: Installing the syslog module uses its configuration before it is written
parent 5a3a0aba
No related branches found
No related tags found
17 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!1896Issue #2940605: Can only intentionally re-render an entity with references 20 times,!1101Issue #2412669 by claudiu.cristea, Julfabre, sidharrell, catch, daffie,...,!1039Issue #2556069 by claudiu.cristea, bnjmnm, lauriii, pfrenssen, Tim Bozeman,...,!10223132456: Fix issue where views instances are emptied before an ajax request is complete,!1012Issue #3226887: Hreflang on non-canonical content pages,!872Draft: Issue #3221319: Race condition when creating menu links and editing content deletes menu links,!594Put each entity type table into a details element on admin/config/regional/content-language,!579Issue #2230909: Simple decimals fail to pass validation,!560Move callback classRemove outside of the loop,!555Issue #3202493,!512Issue #3207771: Menu UI node type form documentation points to non-existent function,!485Sets the autocomplete attribute for username/password input field on login form.,!449Issue #2784233: Allow multiple vocabularies in the taxonomy filter,!231Issue #2671162: summary text wysiwyg patch working fine on 9.2.0-dev,!43Resolve #3173180: Add UI for 'loading' html attribute to images,!30Issue #3182188: Updates composer usage to point at ./vendor/bin/composer
......@@ -63,6 +63,14 @@ protected function openConnection() {
public function log($level, $message, array $context = []) {
global $base_url;
$format = $this->config->get('format');
// If no format is configured then a message will not be written to syslog
// so return early. This occurs during installation of the syslog module
// before configuration has been written.
if (empty($format)) {
return;
}
// Ensure we have a connection available.
$this->openConnection();
......@@ -70,7 +78,7 @@ public function log($level, $message, array $context = []) {
$message_placeholders = $this->parser->parseMessagePlaceholders($message, $context);
$message = empty($message_placeholders) ? $message : strtr($message, $message_placeholders);
$entry = strtr($this->config->get('format'), [
$entry = strtr($format, [
'!base_url' => $base_url,
'!timestamp' => $context['timestamp'],
'!type' => $context['channel'],
......
......@@ -55,6 +55,7 @@ function syslog_form_system_logging_settings_alter(&$form, FormStateInterface $f
'#type' => 'textarea',
'#title' => t('Syslog format'),
'#default_value' => $config->get('format'),
'#required' => TRUE,
'#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>'),
];
......
......@@ -51,6 +51,15 @@ public function testSyslogWriting() {
$this->assertEquals('42', $log[6]);
$this->assertEquals('/my-link', $log[7]);
$this->assertEquals('My warning message.', $log[8]);
// Test that an empty format prevents writing to the syslog.
/** @var \Drupal\Core\Config\Config $config */
$config = $this->container->get('config.factory')->getEditable('syslog.settings');
$config->set('format', '');
$config->save();
unlink($log_filename);
\Drupal::logger('my_module')->warning('My warning message.', ['link' => '/my-link']);
$this->assertFileDoesNotExist($log_filename);
}
/**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment