Issue #3333215 by enchufe, arunkumark, mfb, Nitin shrivastava, smustgrave, cilefen: Return early if syslog configs are NULL to avoid openlog deprecation

merge-requests/4404/head
catch 2023-07-14 08:00:13 +01:00
parent 3950243518
commit 5ce13375ca
2 changed files with 23 additions and 1 deletions

View File

@ -52,8 +52,13 @@ class SysLog implements LoggerInterface {
*/
protected function openConnection() {
if (!$this->connectionOpened) {
// Do not connect if identity or facility are not configured.
$identity = $this->config->get('identity');
$facility = $this->config->get('facility');
$this->connectionOpened = openlog($this->config->get('identity'), LOG_NDELAY, $facility);
if ($identity === NULL || $facility === NULL) {
return;
}
$this->connectionOpened = openlog($identity, LOG_NDELAY, $facility);
}
}
@ -73,6 +78,9 @@ class SysLog implements LoggerInterface {
// Ensure we have a connection available.
$this->openConnection();
if (!$this->connectionOpened) {
return;
}
// Populate the message placeholders and then replace them in the message.
$message_placeholders = $this->parser->parseMessagePlaceholders($message, $context);

View File

@ -62,6 +62,20 @@ class SyslogTest extends KernelTestBase {
$this->assertFileDoesNotExist($log_filename);
}
/**
* Tests that missing facility prevents writing to the syslog.
*
* @covers ::openConnection
*/
public function testSyslogMissingFacility() {
$config = $this->container->get('config.factory')->getEditable('syslog.settings');
$config->clear('facility');
$config->save();
\Drupal::logger('my_module')->warning('My warning message.');
$log_filename = $this->container->get('file_system')->realpath('public://syslog.log');
$this->assertFileDoesNotExist($log_filename);
}
/**
* Tests severity level logging.
*