Elgg  Version 3.0
ErrorHandler.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Elgg\Cli;
4 
5 use Elgg\Logger;
12 
16 class ErrorHandler extends AbstractProcessingHandler {
17 
21  protected $stdout;
22 
26  protected $stderr;
27 
31  static $verbosityLevelMap = [
32  OutputInterface::VERBOSITY_QUIET => Logger::OFF,
33  OutputInterface::VERBOSITY_NORMAL => Logger::WARNING,
34  OutputInterface::VERBOSITY_VERBOSE => Logger::NOTICE,
35  OutputInterface::VERBOSITY_VERY_VERBOSE => Logger::INFO,
36  OutputInterface::VERBOSITY_DEBUG => Logger::DEBUG,
37  ];
38 
46  public function __construct(
47  OutputInterface $stdout,
48  OutputInterface $stderr = null,
49  $bubble = true
50  ) {
51 
52  $this->stdout = $stdout;
53  $this->stderr = $stderr ? : $stdout;
54 
55  $verbosity = $this->stdout->getVerbosity() ? : OutputInterface::VERBOSITY_NORMAL;
56 
57  $level = self::$verbosityLevelMap[$verbosity];
58 
59  parent::__construct($level, $bubble);
60  }
61 
65  public function write(array $record) {
66  $stream = $record['level'] >= Logger::ERROR ? $this->stderr : $this->stdout;
67 
68  $stream->write($record['formatted'], true);
69 
70  if ($stream instanceof StreamOutput) {
71  $dumper = new CliDumper($stream->getStream());
72  $cloner = new VarCloner();
73 
74  if (!empty($record['context'])) {
75  $dumper->dump($cloner->cloneVar($record['context']));
76  }
77 
78  if (!empty($record['extra'])) {
79  $dumper->dump($cloner->cloneVar($record['extra']));
80  }
81  }
82  }
83 
87  public function getDefaultFormatter() {
88  return new ErrorFormatter();
89  }
90 
94  public function close() {
95  $this->stdout = new NullOutput();
96  $this->stderr = new NullOutput();
97  }
98 }
__construct(OutputInterface $stdout, OutputInterface $stderr=null, $bubble=true)
Constructor.
write(array $record)
{}
const OFF
Definition: Logger.php:29
elgg ajax ERROR
Definition: ajax.js:33
Format errors for console output.
Console handler.