php-bug-catcher/reporter-bundle

用于向Bug Catcher报告异常的Symfony扩展包

v2.0.2 2024-09-04 16:16 UTC

This package is auto-updated.

Last update: 2024-09-10 14:30:56 UTC


README

Tests Coverage Status


捕获您Symfony应用程序中的每一个错误

安装

确保全局已安装Composer,如Composer文档中的安装章节所述。

使用Symfony Flex的应用程序

打开命令行,进入您的项目目录,执行

$ composer require php-sentinel/reporter-bundle

versions

未使用Symfony Flex的应用程序

步骤 1: 下载扩展包

打开命令行,进入您的项目目录,执行以下命令以下载此扩展包的最新稳定版本

$ composer require php-sentinel/bug-catcher-reporter-bundle

步骤 2: 启用扩展包

然后,通过将其添加到项目中config/bundles.php文件中注册的扩展包列表中来启用扩展包

// config/bundles.php

return [
    BugCatcher\Reporter\BugCatcherReporterBundle::class => ['all' => true],
];

配置

如果您想通过HTTP请求发送捕获的错误

composer require symfony/http-client
# config/packages/bug_catcher.yaml
services:
    app.chain_uri_catcher:
        class: BugCatcher\Reporter\UrlCatcher\ChainUriCatcher
        arguments:
            $uriCatchers:
                - '@bug_catcher.uri_catcher.http_catcher'
                - '@bug_catcher.uri_catcher.console_catcher'
framework:
    http_client:
        scoped_clients:
            # only requests matching scope will use these options
            bug_catcher.client:
                base_uri: 'https://your-bug-catcher-instance:8000'
bug_catcher:
    project: 'dev'
    http_client: 'bug_catcher.client'
    uri_cather: 'app.chain_uri_catcher'

通过monolog自动记录

composer require symfony/monolog-bundle
# config/packages/monolog.yaml
monolog:
    handlers:
        bug_catcher:
            type: service
            id: bug_catcher.handler
            level: 500

自定义记录

class Foo {
	public function __construct(private readonly BugCatcherInterface $bugCatcher) {
		
	}
	
	public function foo():void {
		$this->bugCatcher->log([
			"message"     => "My message",
			"level"       => 500,
			"projectCode" => "dev",
			"requestUri"  => "my uri",
		]);
		$this->bugCatcher->logRecord("My log record", 500);
		$this->bugCatcher->logException(new \Exception("My Exception"));
	}
}