function SysLog::log

Same name in other branches
  1. 9 core/modules/syslog/src/Logger/SysLog.php \Drupal\syslog\Logger\SysLog::log()
  2. 8.9.x core/modules/syslog/src/Logger/SysLog.php \Drupal\syslog\Logger\SysLog::log()
  3. 10 core/modules/syslog/src/Logger/SysLog.php \Drupal\syslog\Logger\SysLog::log()

Overrides RfcLoggerTrait::log

File

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

Class

SysLog
Redirects logging messages to syslog.

Namespace

Drupal\syslog\Logger

Code

public function log($level, string|\Stringable $message, array $context = []) : void {
    global $base_url;
    $format = $this->config
        ->get('format');
    // If no format is configured then a message will not be written to syslog
    // so return early. This occurs during installation of the syslog module
    // before configuration has been written.
    if (empty($format)) {
        return;
    }
    // Ensure we have a connection available.
    $this->openConnection();
    if (!$this->connectionOpened) {
        return;
    }
    // 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($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);
}

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