function LoggerChannel::log

Same name and namespace in other branches
  1. 8.9.x core/lib/Drupal/Core/Logger/LoggerChannel.php \Drupal\Core\Logger\LoggerChannel::log()
  2. 10 core/lib/Drupal/Core/Logger/LoggerChannel.php \Drupal\Core\Logger\LoggerChannel::log()
  3. 11.x core/lib/Drupal/Core/Logger/LoggerChannel.php \Drupal\Core\Logger\LoggerChannel::log()
1 method overrides LoggerChannel::log()
TestSystemLoggerChannel::log in core/modules/system/tests/modules/advisory_feed_test/src/TestSystemLoggerChannel.php

File

core/lib/Drupal/Core/Logger/LoggerChannel.php, line 94

Class

LoggerChannel
Defines a logger channel that most implementations will use.

Namespace

Drupal\Core\Logger

Code

public function log($level, $message, array $context = []) {
    if ($this->callDepth == self::MAX_CALL_DEPTH) {
        return;
    }
    $this->callDepth++;
    // Merge in defaults.
    $context += [
        'channel' => $this->channel,
        'link' => '',
        'uid' => 0,
        'request_uri' => '',
        'referer' => '',
        'ip' => '',
        'timestamp' => time(),
    ];
    // Some context values are only available when in a request context.
    if ($this->requestStack && ($request = $this->requestStack
        ->getCurrentRequest())) {
        $context['request_uri'] = $request->getUri();
        $context['referer'] = $request->headers
            ->get('Referer', '');
        $context['ip'] = $request->getClientIP() ?: '';
        if ($this->currentUser) {
            $context['uid'] = $this->currentUser
                ->id();
        }
    }
    if (is_string($level)) {
        // Convert to integer equivalent for consistency with RFC 5424.
        $level = $this->levelTranslation[$level];
    }
    // Call all available loggers.
    foreach ($this->sortLoggers() as $logger) {
        $logger->log($level, $message, $context);
    }
    $this->callDepth--;
}

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