class DrupalConsoleLogger
Same name and namespace in other branches
- 11.x core/lib/Drupal/Core/Command/DrupalConsoleLogger.php \Drupal\Core\Command\DrupalConsoleLogger
Logs to the console. A logger is set during DrupalApplication->bootstrap().
Hierarchy
- class \Drupal\Core\Command\DrupalConsoleLogger implements \Psr\Log\LoggerAwareInterface uses \Psr\Log\LoggerAwareTrait extends \Psr\Log\AbstractLogger
Expanded class hierarchy of DrupalConsoleLogger
1 file declares its use of DrupalConsoleLogger
- ConsoleSubscriber.php in core/
lib/ Drupal/ Core/ Command/ EventSubscriber/ ConsoleSubscriber.php
1 string reference to 'DrupalConsoleLogger'
- core.services.yml in core/
core.services.yml - core/core.services.yml
1 service uses DrupalConsoleLogger
File
-
core/
lib/ Drupal/ Core/ Command/ DrupalConsoleLogger.php, line 18
Namespace
Drupal\Core\CommandView source
class DrupalConsoleLogger extends AbstractLogger implements LoggerAwareInterface {
use LoggerAwareTrait;
public function __construct(protected LogMessageParserInterface $parser) {
}
/**
* {@inheritdoc}
*/
public function log($level, $message, array $context = []) : void {
// Populate the message placeholders and then replace them in the message.
$message_placeholders = $this->parser
->parseMessagePlaceholders($message, $context);
$message = empty($message_placeholders) ? $message : strtr($message, $message_placeholders);
$this->logger?->log(self::toPsr3($level), $message, []);
}
/**
* Returns the PSR-3 log level for a given RFC 5424 severity level.
*
* @param int $level
* The RFC 5424 severity level.
*
* @return string
* A PSR-3 log level.
*
* @throws \Psr\Log\InvalidArgumentException
* If the severity level is not recognized.
*/
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}"),
};
}
/**
* A custom map where notices are printed by default.
*/
public static function verbosityLevelMap() : array {
return [
LogLevel::EMERGENCY => OutputInterface::VERBOSITY_NORMAL,
LogLevel::ALERT => OutputInterface::VERBOSITY_NORMAL,
LogLevel::CRITICAL => OutputInterface::VERBOSITY_NORMAL,
LogLevel::ERROR => OutputInterface::VERBOSITY_NORMAL,
LogLevel::WARNING => OutputInterface::VERBOSITY_NORMAL,
LogLevel::NOTICE => OutputInterface::VERBOSITY_NORMAL,
LogLevel::INFO => OutputInterface::VERBOSITY_VERY_VERBOSE,
LogLevel::DEBUG => OutputInterface::VERBOSITY_DEBUG,
];
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.