codex-team / hawk.symfony
Hawk.so 的 Symfony 错误捕获模块
0.0.3
2024-09-23 08:45 UTC
Requires
- php: ^7.2 || ^8.0
- codex-team/hawk.php: ^2.2.2
- guzzlehttp/guzzle: ^6.0 || ^7.0
- jean85/pretty-package-versions: ^1.5 || ^2.0
- monolog/monolog: ^2.2 || ^3.0
- php-http/discovery: ^1.15
- symfony/config: ^4.4.20||^5.0.11||^6.0||^7.0
- symfony/dependency-injection: ^4.4.20||^5.0.11||^6.0||^7.0
- symfony/http-kernel: ^4.4.20||^5.0.11||^6.0||^7.0
- symfony/psr-http-message-bridge: ^1.2||^2.0||^6.4||^7.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.19||^3.40
This package is auto-updated.
Last update: 2024-09-23 13:21:34 UTC
README
Symfony 错误捕获模块,适用于 Hawk.so。
设置
捕获器支持 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
文件中,指定相应部分(dev
或 prod
)下的处理程序设置
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