function ConsoleSubscriber::onCommand

Same name and namespace in other branches
  1. main core/lib/Drupal/Core/Command/EventSubscriber/ConsoleSubscriber.php \Drupal\Core\Command\EventSubscriber\ConsoleSubscriber::onCommand()

Set a logger so that log messages appear in console output.

Parameters

\Symfony\Component\Console\Event\ConsoleCommandEvent $event: The event.

File

core/lib/Drupal/Core/Command/EventSubscriber/ConsoleSubscriber.php, line 30

Class

ConsoleSubscriber
Set a logger so that log messages appear in console output.

Namespace

Drupal\Core\Command\EventSubscriber

Code

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()));
}

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