You are here

public function SyslogTest::testSyslogSeverity in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/syslog/tests/src/Kernel/SyslogTest.php \Drupal\Tests\syslog\Kernel\SyslogTest::testSyslogSeverity()

Test severity level logging.

@covers ::log

File

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

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