Elgg  Version master
ErrorHandler.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Elgg\Cli;
4 
5 use Elgg\Logger;
6 use Monolog\Handler\AbstractProcessingHandler;
7 use Monolog\Level;
8 use Monolog\LogRecord;
9 use Symfony\Component\Console\Output\NullOutput;
10 use Symfony\Component\Console\Output\OutputInterface;
11 use Symfony\Component\Console\Output\StreamOutput;
12 use Symfony\Component\VarDumper\Cloner\VarCloner;
13 use Symfony\Component\VarDumper\Dumper\CliDumper;
14 use Monolog\Formatter\FormatterInterface;
15 
19 class ErrorHandler extends AbstractProcessingHandler {
20 
22  OutputInterface::VERBOSITY_QUIET => Logger::OFF,
23  OutputInterface::VERBOSITY_NORMAL => Level::Warning,
24  OutputInterface::VERBOSITY_VERBOSE => Level::Notice,
25  OutputInterface::VERBOSITY_VERY_VERBOSE => Level::Info,
26  OutputInterface::VERBOSITY_DEBUG => Level::Debug,
27  ];
28 
32  protected $stdout;
33 
37  protected $stderr;
38 
46  public function __construct(
47  OutputInterface $stdout,
48  ?OutputInterface $stderr = null,
49  $bubble = true
50  ) {
51  $this->stdout = $stdout;
52  $this->stderr = $stderr ?: $stdout;
53 
54  $verbosity = $this->stdout->getVerbosity() ?: OutputInterface::VERBOSITY_NORMAL;
55 
56  $level = self::VERBOSITY_LEVEL_MAP[$verbosity];
57 
58  parent::__construct($level, $bubble);
59  }
60 
64  public function write(LogRecord $record): void {
65  $stream = $record->level->value >= Level::Error ? $this->stderr : $this->stdout;
66 
67  $stream->write($record->formatted, true);
68 
69  if ($stream instanceof StreamOutput) {
70  $dumper = new CliDumper($stream->getStream());
71  $cloner = new VarCloner();
72 
73  if (!empty($record->context)) {
74  $dumper->dump($cloner->cloneVar($record->context));
75  }
76 
77  if (!empty($record->extra)) {
78  $dumper->dump($cloner->cloneVar($record->extra));
79  }
80  }
81  }
82 
86  public function getDefaultFormatter(): FormatterInterface {
87  return new ErrorFormatter();
88  }
89 
93  public function close(): void {
94  $this->stdout = new NullOutput();
95  $this->stderr = new NullOutput();
96  }
97 }
return[ 'admin/delete_admin_notices'=>['access'=> 'admin'], 'admin/menu/save'=>['access'=> 'admin'], 'admin/plugins/activate'=>['access'=> 'admin'], 'admin/plugins/activate_all'=>['access'=> 'admin'], 'admin/plugins/deactivate'=>['access'=> 'admin'], 'admin/plugins/deactivate_all'=>['access'=> 'admin'], 'admin/plugins/set_priority'=>['access'=> 'admin'], 'admin/security/security_txt'=>['access'=> 'admin'], 'admin/security/settings'=>['access'=> 'admin'], 'admin/security/regenerate_site_secret'=>['access'=> 'admin'], 'admin/site/cache/invalidate'=>['access'=> 'admin'], 'admin/site/flush_cache'=>['access'=> 'admin'], 'admin/site/icons'=>['access'=> 'admin'], 'admin/site/set_maintenance_mode'=>['access'=> 'admin'], 'admin/site/set_robots'=>['access'=> 'admin'], 'admin/site/theme'=>['access'=> 'admin'], 'admin/site/unlock_upgrade'=>['access'=> 'admin'], 'admin/site/settings'=>['access'=> 'admin'], 'admin/upgrade'=>['access'=> 'admin'], 'admin/upgrade/reset'=>['access'=> 'admin'], 'admin/user/ban'=>['access'=> 'admin'], 'admin/user/bulk/ban'=>['access'=> 'admin'], 'admin/user/bulk/delete'=>['access'=> 'admin'], 'admin/user/bulk/unban'=>['access'=> 'admin'], 'admin/user/bulk/validate'=>['access'=> 'admin'], 'admin/user/change_email'=>['access'=> 'admin'], 'admin/user/delete'=>['access'=> 'admin'], 'admin/user/login_as'=>['access'=> 'admin'], 'admin/user/logout_as'=>[], 'admin/user/makeadmin'=>['access'=> 'admin'], 'admin/user/resetpassword'=>['access'=> 'admin'], 'admin/user/removeadmin'=>['access'=> 'admin'], 'admin/user/unban'=>['access'=> 'admin'], 'admin/user/validate'=>['access'=> 'admin'], 'annotation/delete'=>[], 'avatar/upload'=>[], 'comment/save'=>[], 'diagnostics/download'=>['access'=> 'admin'], 'entity/chooserestoredestination'=>[], 'entity/delete'=>[], 'entity/mute'=>[], 'entity/restore'=>[], 'entity/subscribe'=>[], 'entity/trash'=>[], 'entity/unmute'=>[], 'entity/unsubscribe'=>[], 'login'=>['access'=> 'logged_out'], 'logout'=>[], 'notifications/mute'=>['access'=> 'public'], 'plugins/settings/remove'=>['access'=> 'admin'], 'plugins/settings/save'=>['access'=> 'admin'], 'plugins/usersettings/save'=>[], 'register'=>['access'=> 'logged_out', 'middleware'=>[\Elgg\Router\Middleware\RegistrationAllowedGatekeeper::class,],], 'river/delete'=>[], 'settings/notifications'=>[], 'settings/notifications/subscriptions'=>[], 'user/changepassword'=>['access'=> 'public'], 'user/requestnewpassword'=>['access'=> 'public'], 'useradd'=>['access'=> 'admin'], 'usersettings/save'=>[], 'widgets/add'=>[], 'widgets/delete'=>[], 'widgets/move'=>[], 'widgets/save'=>[],]
Definition: actions.php:73
Format errors for console output.
Console handler.
__construct(OutputInterface $stdout, ?OutputInterface $stderr=null, $bubble=true)
Constructor.
write(LogRecord $record)
{}
const OFF
Definition: Logger.php:30
$data value
Definition: default.php:23