php-bug-catcher/bug-catcher-reporter-bundle

一个用于向Bug Catcher报告异常的Symfony组件

安装: 85

依赖者: 0

建议者: 0

安全: 0

星标: 0

关注者: 1

分支: 0

开放问题: 0

类型:symfony-bundle

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"));
	}
}