Elgg  Version 5.1
ErrorHandler.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Elgg\Cli;
4 
5 use Elgg\Logger;
13 
17 class ErrorHandler extends AbstractProcessingHandler {
18 
20  OutputInterface::VERBOSITY_QUIET => Logger::OFF,
21  OutputInterface::VERBOSITY_NORMAL => Logger::WARNING,
22  OutputInterface::VERBOSITY_VERBOSE => Logger::NOTICE,
23  OutputInterface::VERBOSITY_VERY_VERBOSE => Logger::INFO,
24  OutputInterface::VERBOSITY_DEBUG => Logger::DEBUG,
25  ];
26 
30  protected $stdout;
31 
35  protected $stderr;
36 
44  public function __construct(
45  OutputInterface $stdout,
46  OutputInterface $stderr = null,
47  $bubble = true
48  ) {
49  $this->stdout = $stdout;
50  $this->stderr = $stderr ?: $stdout;
51 
52  $verbosity = $this->stdout->getVerbosity() ?: OutputInterface::VERBOSITY_NORMAL;
53 
54  $level = self::VERBOSITY_LEVEL_MAP[$verbosity];
55 
56  parent::__construct($level, $bubble);
57  }
58 
62  public function write(array $record): void {
63  $stream = $record['level'] >= Logger::ERROR ? $this->stderr : $this->stdout;
64 
65  $stream->write($record['formatted'], true);
66 
67  if ($stream instanceof StreamOutput) {
68  $dumper = new CliDumper($stream->getStream());
69  $cloner = new VarCloner();
70 
71  if (!empty($record['context'])) {
72  $dumper->dump($cloner->cloneVar($record['context']));
73  }
74 
75  if (!empty($record['extra'])) {
76  $dumper->dump($cloner->cloneVar($record['extra']));
77  }
78  }
79  }
80 
84  public function getDefaultFormatter(): FormatterInterface {
85  return new ErrorFormatter();
86  }
87 
91  public function close(): void {
92  $this->stdout = new NullOutput();
93  $this->stderr = new NullOutput();
94  }
95 }
__construct(OutputInterface $stdout, OutputInterface $stderr=null, $bubble=true)
Constructor.
c Accompany it with the information you received as to the offer to distribute corresponding source complete source code means all the source code for all modules it plus any associated interface definition plus the scripts used to control compilation and installation of the executable as a special the source code distributed need not include anything that is normally and so on of the operating system on which the executable unless that component itself accompanies the executable If distribution of executable or object code is made by offering access to copy from a designated then offering equivalent access to copy the source code from the same place counts as distribution of the source even though third parties are not compelled to copy the source along with the object code You may not or distribute the Program except as expressly provided under this License Any attempt otherwise to sublicense or distribute the Program is void
Definition: LICENSE.txt:215
write(array $record)
{}
const OFF
Definition: Logger.php:29
Format errors for console output.
Console handler.