Issue #3333215 by enchufe, arunkumark, mfb, Nitin shrivastava, smustgrave, cilefen: Return early if syslog configs are NULL to avoid openlog deprecation
parent
3950243518
commit
5ce13375ca
|
@ -52,8 +52,13 @@ class SysLog implements LoggerInterface {
|
||||||
*/
|
*/
|
||||||
protected function openConnection() {
|
protected function openConnection() {
|
||||||
if (!$this->connectionOpened) {
|
if (!$this->connectionOpened) {
|
||||||
|
// Do not connect if identity or facility are not configured.
|
||||||
|
$identity = $this->config->get('identity');
|
||||||
$facility = $this->config->get('facility');
|
$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.
|
// Ensure we have a connection available.
|
||||||
$this->openConnection();
|
$this->openConnection();
|
||||||
|
if (!$this->connectionOpened) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Populate the message placeholders and then replace them in the message.
|
// Populate the message placeholders and then replace them in the message.
|
||||||
$message_placeholders = $this->parser->parseMessagePlaceholders($message, $context);
|
$message_placeholders = $this->parser->parseMessagePlaceholders($message, $context);
|
||||||
|
|
|
@ -62,6 +62,20 @@ class SyslogTest extends KernelTestBase {
|
||||||
$this->assertFileDoesNotExist($log_filename);
|
$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.
|
* Tests severity level logging.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue