Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ConsoleLogger.php
Go to the documentation of this file.
1 <?php
8 
9 use Symfony\Component\Console\Output\OutputInterface;
10 use Symfony\Component\Console\Formatter\OutputFormatterStyle;
11 
18 {
24  private $isInline = false;
25 
31  protected $console;
32 
38  public function __construct(OutputInterface $output)
39  {
40  $this->console = $output;
41  $outputFormatter = $this->console->getFormatter();
42  $outputFormatter->setStyle('detail', new OutputFormatterStyle('blue'));
43  $outputFormatter->setStyle('metadata', new OutputFormatterStyle('cyan'));
44  }
45 
49  public function logSuccess($message)
50  {
51  $this->terminateLine();
52  $this->console->writeln("<info>[SUCCESS]" . ($message ? ": $message" : '') . '</info>');
53  }
54 
58  public function logError(\Exception $e)
59  {
60  $this->terminateLine();
61  $this->console->writeln("<error>[ERROR]: " . $e . '</error>');
62  }
63 
67  public function log($message)
68  {
69  $this->terminateLine();
70  $this->console->writeln('<detail>' . $message . '</detail>');
71  }
72 
76  public function logInline($message)
77  {
78  $this->isInline = true;
79  $this->console->write('<detail>' . $message . '</detail>');
80  }
81 
85  public function logMeta($message)
86  {
87  $this->terminateLine();
88  $this->console->writeln('<metadata>' . $message . '</metadata>');
89  }
90 
96  private function terminateLine()
97  {
98  if ($this->isInline) {
99  $this->isInline = false;
100  $this->console->writeln('');
101  }
102  }
103 }
$message
__construct(OutputInterface $output)