You are here

public function ErrorLogMessageFormatter::log in Logging and alerts 8

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

Overrides RfcLoggerTrait::log

File

errorlog/src/Logger/ErrorLogMessageFormatter.php, line 46

Class

ErrorLogMessageFormatter
Logger class for errorlog module.

Namespace

Drupal\errorlog\Logger

Code

public function log($level, $message, array $context = []) {
  if ($this->config
    ->get('errorlog_' . $level)) {
    $log = [
      'level' => $level,
      'context' => $context,
      'message' => $message,
    ];

    // Send themed alert to the web server's log.
    if (\Drupal::hasService('theme.manager')) {
      $errorlog_theme_element = [
        '#theme' => 'errorlog_format',
        '#log' => $log,
      ];
      $message = $this->renderer
        ->renderPlain($errorlog_theme_element);
    }
    error_log($message, 0);
  }
}