function DrupalConsoleLogger::toPsr3

Same name and namespace in other branches
  1. 11.x core/lib/Drupal/Core/Command/DrupalConsoleLogger.php \Drupal\Core\Command\DrupalConsoleLogger::toPsr3()

Returns the PSR-3 log level for a given RFC 5424 severity level.

Parameters

int $level: The RFC 5424 severity level.

Return value

string A PSR-3 log level.

Throws

\Psr\Log\InvalidArgumentException If the severity level is not recognized.

File

core/lib/Drupal/Core/Command/DrupalConsoleLogger.php, line 47

Class

DrupalConsoleLogger
Logs to the console. A logger is set during DrupalApplication->bootstrap().

Namespace

Drupal\Core\Command

Code

public static function toPsr3(int $level) : string {
  return match ($level) {  RfcLogLevel::EMERGENCY => LogLevel::EMERGENCY,
    RfcLogLevel::ALERT => LogLevel::ALERT,
    RfcLogLevel::CRITICAL => LogLevel::CRITICAL,
    RfcLogLevel::ERROR => LogLevel::ERROR,
    RfcLogLevel::WARNING => LogLevel::WARNING,
    RfcLogLevel::NOTICE => LogLevel::NOTICE,
    RfcLogLevel::INFO => LogLevel::INFO,
    RfcLogLevel::DEBUG => LogLevel::DEBUG,
    default => throw new \InvalidArgumentException("Invalid log level: {$level}"),
  
  };
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.