我有一个项目,我正在使用JMose's Command Scheduler Bundle来创建一个cronjob经理。 cronjob管理器处理我自己的自定义Symfony命令解析:source。
问题是这个repo正在处理Exceptions并在命令控制台上抛出错误,如果它包含了$ e-> getLine()方法,那么它将非常整洁,以便将异常消息与生成它的行一起打印。你可以在下面看到他的代码。
try {
$output->writeln('<info>Execute</info> : <comment>' . $scheduledCommand->getCommand()
. ' ' . $scheduledCommand->getArguments() . '</comment>');
$result = $command->run($input, $logOutput);
} catch (\Exception $e) {
$logOutput->writeln($e->getMessage());
$logOutput->writeln($e->getTraceAsString());
$result = -1;
}
我想要的是覆盖他的类,以添加该行代码。我试过没有运气,我无法在Symfony文档网站上找到帮助。
我当前的项目结构看起来像那样。我突出显示了类ExecuteCommand,因为它是我想要覆盖的类。
以详细模式运行命令:
php bin/console parse:source -v
使用Symfony控制台事件:https://symfony.com/doc/3.4/components/console/events.html
有一个名为:EXCEPTION
或console.exception
的事件,您可以捕获任何命令异常。