Skip to content

Commit

Permalink
Document deduplicating exceptions (#9026)
Browse files Browse the repository at this point in the history
* Document deduplicating exceptions

* formatting

* formatting

---------

Co-authored-by: Taylor Otwell <[email protected]>
  • Loading branch information
timacdonald and taylorotwell authored Sep 13, 2023
1 parent b9cfe7d commit c5ff3ca
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions errors.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,42 @@ Sometimes you may need to report an exception but continue handling the current
}
}

<a name="deduplicating-reported-exceptions"></a>
#### Deduplicating Reported Exceptions

If you are using the `report` function throughout your application, you may occasionally report the same exception multiple times, creating duplicate entries in your logs.

If you would like to ensure that a single instance of an exception is only ever reported once, you may call the exception handler's `dontReportDuplicates` method. Typically, this method should be invoked from the `boot` method of your application's `AppServiceProvider`:

```php
use Illuminate\Contracts\Debug\ExceptionHandler;

/**
* Bootstrap any application services.
*/
public function boot(ExceptionHandler $exceptionHandler): void
{
$exceptionHandler->dontReportDuplicates();
}
```

Now, when the `report` helper is called with the same instance of an exception, only the first call will be reported:

```php
$original = new RuntimeException('Whoops!');

report($original); // reported

try {
throw $original;
} catch (Throwable $caught) {
report($caught); // ignored
}

report($original); // ignored
report($caught); // ignored
```

<a name="exception-log-levels"></a>
### Exception Log Levels

Expand Down

0 comments on commit c5ff3ca

Please sign in to comment.