codex-team / hawk.symfony

Hawk.so 的 Symfony 错误捕获模块

0.0.3 2024-09-23 08:45 UTC

This package is auto-updated.

Last update: 2024-09-23 13:21:34 UTC


README

Symfony 错误捕获模块,适用于 Hawk.so

设置

  1. 注册 账户,创建项目并获取集成令牌。

  2. 通过 composer 安装 SDK 以安装捕获器

捕获器支持 PHP 7.2 或更高版本

$ composer require codex-team/hawk.symfony

配置

将以下授权信息添加到您的 .env 文件中

HAWK_TOKEN=<your_token_from_the_control_panel>

config/packages/hawk.yaml 创建配置文件,内容如下

HawkBundle\HawkBundle::class => ['all' => true]

config/packages/monolog.yaml 文件中,指定相应部分(devprod)下的处理程序设置

hawk:
  type: service
  id: HawkBundle\Monolog\Handler
  level: error

向错误报告中添加用户信息

$this->catcher->setUser([
    'name' => 'user name',
    'photo' => 'user photo',
]);

$this->catcher->setContext([
    // Additional context information
]);

手动发送异常

要手动发送异常,请通过依赖注入(DI)初始化 __construct(\HawkBundle\Catcher $catcher) 类,并使用以下方法

$this->catcher->sendException($exception);

发送自定义消息

您还可以使用 ->sendMessage(...) 方法发送自定义消息

$this->catcher->sendMessage(
    'your message', 
    [
        // Additional context information
    ]
);

示例:手动发送

private $catcher;

public function __construct(\HawkBundle\Catcher $catcher) 
{
    $this->catcher = $catcher;
}

public function test()
{
    try {
        // The code where you need to catch the error
    } catch (\Exception $exception) {
        $this->catcher->sendException($exception);
    }
}

问题和改进

请随时提问或改进项目。

链接

仓库: https://github.com/codex-team/hawk.symfony

报告错误: https://github.com/codex-team/hawk.symfony/issues

Composer 包: https://packagist.org.cn/packages/codex-team/hawk.symfony

CodeX Team: https://codex.so

许可证

MIT