public function DrushLog::log

8.0.x DrushLog.php public DrushLog::log($level, $message, array $context = array())
7.x DrushLog.php public DrushLog::log($level, $message, array $context = array())
master DrushLog.php public DrushLog::log($level, $message, array $context = array())

File

lib/Drush/Log/DrushLog.php, line 39
Contains \Drush\Log\DrushLog.

Namespace

Drush\Log

Class

DrushLog
Redirects Drupal logging messages to Drush log.

Code

public function log($level, $message, array $context = array()) {
  // Translate the RFC logging levels into their Drush counterparts, more or
  // less.
  // @todo ALERT, CRITICAL and EMERGENCY are considered show-stopping errors,
  // and they should cause Drush to exit or panic. Not sure how to handle this,
  // though.
  switch ($level) {
    case LogLevel::ALERT:
    case LogLevel::CRITICAL:
    case LogLevel::EMERGENCY:
    case LogLevel::ERROR:
      $error_type = 'error';
      break;

    case LogLevel::WARNING:
      $error_type = 'warning';
      break;

    case LogLevel::DEBUG:
    case LogLevel::INFO:
    case LogLevel::NOTICE:
      $error_type = 'notice';
      break;

      // TODO: Unknown log levels that are not defined
      // in Psr\Log\LogLevel SHOULD NOT be used.  See
      // https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-3-logger-interface.md
      // We should convert these to 'notice'.
    default:
      $error_type = $level;
      break;
  }
  drush_log($message, $error_type);
}