我有这个简单的控制台程序:namespace MyApp\Console;use Symfony\Component\Console\Command\Command;use Symfony\Component\Console\Input\InputArgument;class MaConsole extends Command { protected function configure() { $this->setDescription('Console\'s not console'); } protected function execute( \Symfony\Component\Console\Input\InputInterface $input, \Symfony\Component\Console\Output\OutputInterface $output ) { $output->writeln('Doing Stuff'); }}我像这样加载它:namespace MyApp;use Symfony\Component\Console\Application as SymfonyApplication;use MyApp\Console\MaConsole;class Application extends SymfonyApplication{ public function __construct( string $name = 'staff', string $version = '0.0.1' ) { parent::__construct($name, $version); throw new \Exception('Test Sentry on Playground'); $this->add(new MaConsole()); }}我想在 Sentry 服务中记录上面抛出的异常。所以我的切入点是:use MyApp\Application;require __DIR__ . '/vendor/autoload.php';Sentry\init([ 'dsn' => getenv('SENTRY_DSN'), 'environment' => getenv('ENVIRONMENT')]);$application = (new Application())->run();但是我没有将错误记录到哨兵中,即使我已经设置了正确的环境变量。该应用程序不加载完整的 Symfony 框架,而是仅使用控制台组件,所以我不知道是否应该使用 Sentry Symfony 集成:https : //docs.sentry.io/platforms/php/symfony/原因是因为我不知道在我的情况下如何加载包,因此我使用 SDK。
1 回答
慕田峪9158850
TA贡献1794条经验 获得超7个赞
您可以使用调度程序:
use Symfony\Component\EventDispatcher\EventDispatcher;
$dispatcher = new EventDispatcher();
$dispatcher->addListener(ConsoleEvents::ERROR, function (ConsoleErrorEvent $event) use ($env) {
Sentry\init([
'dsn' => getenv('SENTRY_DSN'),
'environment' => $env
]);
Sentry\captureException($event->getError());
});
$kernel = new AppKernel($env, $debug);
$application = new Application($kernel);
$application->setDispatcher($dispatcher);
$application->run($input);
- 1 回答
- 0 关注
- 109 浏览
添加回答
举报
0/150
提交
取消