You are here

public function SysLog::log in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/syslog/src/Logger/SysLog.php \Drupal\syslog\Logger\SysLog::log()

Overrides RfcLoggerTrait::log

File

core/modules/syslog/src/Logger/SysLog.php, line 63

Class

SysLog
Redirects logging messages to syslog.

Namespace

Drupal\syslog\Logger

Code

public function log($level, $message, array $context = []) {
  global $base_url;

  // Ensure we have a connection available.
  $this
    ->openConnection();

  // Populate the message placeholders and then replace them in the message.
  $message_placeholders = $this->parser
    ->parseMessagePlaceholders($message, $context);
  $message = empty($message_placeholders) ? $message : strtr($message, $message_placeholders);
  $entry = strtr($this->config
    ->get('format'), [
    '!base_url' => $base_url,
    '!timestamp' => $context['timestamp'],
    '!type' => $context['channel'],
    '!ip' => $context['ip'],
    '!request_uri' => $context['request_uri'],
    '!referer' => $context['referer'],
    '!severity' => $level,
    '!uid' => $context['uid'],
    '!link' => strip_tags($context['link']),
    '!message' => strip_tags($message),
  ]);
  $this
    ->syslogWrapper($level, $entry);
}