function SyslogTest::testSyslogSeverity

Same name in other branches
  1. 9 core/modules/syslog/tests/src/Kernel/SyslogTest.php \Drupal\Tests\syslog\Kernel\SyslogTest::testSyslogSeverity()
  2. 8.9.x core/modules/syslog/tests/src/Kernel/SyslogTest.php \Drupal\Tests\syslog\Kernel\SyslogTest::testSyslogSeverity()
  3. 10 core/modules/syslog/tests/src/Kernel/SyslogTest.php \Drupal\Tests\syslog\Kernel\SyslogTest::testSyslogSeverity()

Tests severity level logging.

@covers ::log

File

core/modules/syslog/tests/src/Kernel/SyslogTest.php, line 92

Class

SyslogTest
Test syslog logger functionality.

Namespace

Drupal\Tests\syslog\Kernel

Code

public function testSyslogSeverity() : void {
    
    /** @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]);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.