You are here

public function SyslogTest::testSyslogSeverity in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/syslog/tests/src/Kernel/SyslogTest.php \Drupal\Tests\syslog\Kernel\SyslogTest::testSyslogSeverity()
  2. 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 70

Class

SyslogTest
Test syslog logger functionality.

Namespace

Drupal\Tests\syslog\Kernel

Code

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]);
}