You are here

public function DrupalConsoleLog::log in Apigee Edge 8

Overrides RfcLoggerTrait::log

File

src/Command/DrupalConsoleLog.php, line 65

Class

DrupalConsoleLog
Redirects Drupal logging messages to Drupal Console log.

Namespace

Drupal\apigee_edge\Command

Code

public function log($level, $message, array $context = []) {
  switch ($level) {
    case RfcLogLevel::ERROR:
      $error_type = LogLevel::ERROR;
      break;
    case RfcLogLevel::WARNING:
      $error_type = LogLevel::WARNING;
      break;
    case RfcLogLevel::DEBUG:
      $error_type = LogLevel::DEBUG;
      break;
    case RfcLogLevel::INFO:
      $error_type = LogLevel::INFO;
      break;
    case RfcLogLevel::NOTICE:
      $error_type = LogLevel::NOTICE;
      break;
    default:
      $error_type = $level;
      break;
  }
  $message_placeholders = $this->logMessageParser
    ->parseMessagePlaceholders($message, $context);
  $message_placeholders = array_filter($message_placeholders, function ($element) {
    return is_scalar($element) || is_callable([
      $element,
      '__toString',
    ]);
  });
  $message = empty($message_placeholders) ? $message : strtr($message, $message_placeholders);
  $this->logger
    ->log($error_type, $message, $context);
}