Skip to content

Commit

Permalink
Make it easier to log exceptions for child Applications (#102)
Browse files Browse the repository at this point in the history
  • Loading branch information
cspray authored Aug 3, 2020
1 parent fb8c26c commit 27d4654
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Unreleased
## 3.1.0 - 2020-08-02

#### Added

- Added a protected method `AbstractApplication::logException` that logs detailed information about an exception as well
as additional application specific information as context to the Logger.

## 3.0.0 - 2020-08-02

Expand Down
8 changes: 6 additions & 2 deletions src/AbstractApplication.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,18 @@ abstract protected function doStart() : Promise;
* @param Throwable $throwable
*/
public function handleException(Throwable $throwable) : void {
$this->logger->critical($throwable->getMessage(), [
$this->logException($throwable);
}

protected function logException(Throwable $throwable, array $context = []) : void {
$this->logger->critical($throwable->getMessage(), array_merge([], $context, [
'class' => get_class($throwable),
'file' => $throwable->getFile(),
'line' => $throwable->getLine(),
'code' => $throwable->getCode(),
'stack_trace' => $throwable->getTrace(),
'previous' => $this->marshalPreviousExceptions($throwable)
]);
]));
}

private function marshalPreviousExceptions(Throwable $original) : ?array {
Expand Down

0 comments on commit 27d4654

Please sign in to comment.