LoggerChannel::log

public LoggerChannel::log($level, $message, array $context = array())

Logs with an arbitrary level.

Parameters

mixed $level:

string $message:

array $context:

Return value

null

Overrides LoggerTrait::log

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
public function log($level, $message, array $context = array()) {
  if ($this->callDepth == self::MAX_CALL_DEPTH) {
    return;
  }
  $this->callDepth++;
 
  // Merge in defaults.
  $context += array(
    'channel' => $this->channel,
    'link' => '',
    'user' => NULL,
    '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();
    try {
      if ($this->currentUser) {
        $context['user'] = $this->currentUser;
        $context['uid'] = $this->currentUser->id();
      }
    }
    catch (\Exception $e) {
      // An exception might be thrown if the database connection is not
      // available or due to another unexpected reason. It is more important
      // to log the error that we already have so any additional exceptions
      // are ignored.
    }
  }
 
  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--;
}
doc_Drupal
2025-01-10 15:47:30
Comments
Leave a Comment

Please login to continue.