You are here

public function NewRelicLogger::log in New Relic 8

Same name and namespace in other branches
  1. 2.x src/Logger/NewRelicLogger.php \Drupal\new_relic_rpm\Logger\NewRelicLogger::log()
  2. 2.0.x src/Logger/NewRelicLogger.php \Drupal\new_relic_rpm\Logger\NewRelicLogger::log()

File

src/Logger/NewRelicLogger.php, line 106

Class

NewRelicLogger
A Logger that allows sending messages to the New Relic API.

Namespace

Drupal\new_relic_rpm\Logger

Code

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

  // Check if the severity is supposed to be logged.
  if (!$this
    ->shouldLog($level)) {
    return;
  }
  $this->lastLoggedLevel = $level;

  // If we were passed an exception, use that instead.
  if (isset($context['exception'])) {
    $this->adapter
      ->logException($context['exception']);
    return;
  }
  $format = "@message | Severity: (@severity) @severity_desc | Type: @type | Request URI: @request_uri | Referrer URI: @referer_uri | User: @uid | IP Address: @ip";
  $message_placeholders = $this->parser
    ->parseMessagePlaceholders($message, $context);
  $message = strtr($format, [
    '@severity' => $level,
    '@severity_desc' => $this
      ->getSeverityName($level),
    '@type' => $context['channel'],
    '@ip' => $context['ip'],
    '@request_uri' => $context['request_uri'],
    '@referer_uri' => $context['referer'],
    '@uid' => $context['uid'],
    '@message' => strip_tags(strtr($message, $message_placeholders)),
  ]);
  $this->adapter
    ->logError($message);
}