PHPackages                             codex-team/hawk.symfony - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Logging &amp; Monitoring](/categories/logging)
4. /
5. codex-team/hawk.symfony

ActiveLibrary[Logging &amp; Monitoring](/categories/logging)

codex-team/hawk.symfony
=======================

Symfony errors Catcher module for Hawk.so

0.0.10(9mo ago)21.5kMITPHPPHP ^7.2 || ^8.0

Since Sep 17Pushed 9mo ago2 watchersCompare

[ Source](https://github.com/codex-team/hawk.symfony)[ Packagist](https://packagist.org/packages/codex-team/hawk.symfony)[ RSS](/packages/codex-team-hawksymfony/feed)WikiDiscussions main Synced today

READMEChangelog (10)Dependencies (11)Versions (15)Used By (0)

Hawk Symfony
============

[](#hawk-symfony)

Symfony errors Catcher for [Hawk.so](https://hawk.so).

Setup
-----

[](#setup)

1. [Register](https://garage.hawk.so/sign-up) an account, create a Project and get an Integration Token.
2. Install SDK via [composer](https://getcomposer.org) to install the Catcher

Catcher provides support for PHP 7.2 or later

```
$ composer require codex-team/hawk.symfony
```

### Configuration

[](#configuration)

Add the following authorization information to your `.env` file:

```
HAWK_TOKEN=
```

Create a configuration file at `config/packages/hawk.yaml` with the following content:

```
hawk:
  integration_token: '%env(HAWK_TOKEN)%'

  # Optional: Configure a custom beforeSend service
  before_send_service: 'App\Hawk\BeforeSendService'
```

In the `config/packages/monolog.yaml` file, specify the handler settings under the appropriate section (`dev` or `prod`):

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

### Adding User Information to Error Reports:

[](#adding-user-information-to-error-reports)

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

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

### Sending Exceptions Manually:

[](#sending-exceptions-manually)

To manually send exceptions, initialize `__construct(\HawkBundle\Catcher $catcher)` class via dependency injection (DI), and use the following method:

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

### Sending Custom Messages:

[](#sending-custom-messages)

You can also send custom messages using the `->sendMessage(...)` method:

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

### Example: Sending Manually

[](#example-sending-manually)

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

### Example: BeforeSendService Class

[](#example-beforesendservice-class)

If you want to process or modify error data before sending it to Hawk, you can define a custom service by implementing the `BeforeSendServiceInterface`.

```
