class ConsoleSubscriber
Same name and namespace in other branches
- 11.x core/lib/Drupal/Core/Command/EventSubscriber/ConsoleSubscriber.php \Drupal\Core\Command\EventSubscriber\ConsoleSubscriber
Set a logger so that log messages appear in console output.
Hierarchy
- class \Drupal\Core\Command\EventSubscriber\ConsoleSubscriber implements \Symfony\Component\EventDispatcher\EventSubscriberInterface
Expanded class hierarchy of ConsoleSubscriber
File
-
core/
lib/ Drupal/ Core/ Command/ EventSubscriber/ ConsoleSubscriber.php, line 17
Namespace
Drupal\Core\Command\EventSubscriberView source
class ConsoleSubscriber implements EventSubscriberInterface {
public function __construct(protected DrupalConsoleLogger $logger) {
}
/**
* Set a logger so that log messages appear in console output.
*
* @param \Symfony\Component\Console\Event\ConsoleCommandEvent $event
* The event.
*/
public function onCommand(ConsoleCommandEvent $event) : void {
$errorOutput = $event->getOutput();
if ($event->getOutput() instanceof ConsoleOutputInterface) {
$errorOutput = $event->getOutput()
->getErrorOutput();
}
$this->logger
->setLogger(new ConsoleLogger($errorOutput, $this->logger
->verbosityLevelMap()));
}
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents() : array {
$events[ConsoleEvents::COMMAND][] = [
'onCommand',
500,
];
return $events;
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.