From 848555e505a2b379fd95d4252379ae47232947a5 Mon Sep 17 00:00:00 2001 From: Walter Tamboer Date: Wed, 6 Jun 2018 16:22:24 +0200 Subject: [PATCH] Normal PHP errors are also nicely formatted now --- .../HumanReadableExceptionFormatter.php | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/src/Formatter/HumanReadableExceptionFormatter.php b/src/Formatter/HumanReadableExceptionFormatter.php index 0bb9974..e654cd5 100644 --- a/src/Formatter/HumanReadableExceptionFormatter.php +++ b/src/Formatter/HumanReadableExceptionFormatter.php @@ -2,14 +2,13 @@ namespace PolderKnowledge\LogModule\Formatter; -use Monolog\Formatter\FormatterInterface; -use Monolog\Formatter\LineFormatter; +use Monolog\Formatter\NormalizerFormatter; use WShafer\PSR11MonoLog\FactoryInterface; /** * Format an Exception in a similar way PHP does by default when an exception bubbles to the top */ -class HumanReadableExceptionFormatter extends LineFormatter implements FactoryInterface +class HumanReadableExceptionFormatter extends NormalizerFormatter implements FactoryInterface { public function __invoke(array $options) { @@ -22,18 +21,9 @@ public function __invoke(array $options) public function format(array $record): string { - $exception = $record['context']['exception'] ?? null; + $throwable = $record['context']['exception'] ?? null; - if (!$exception) { - return parent::format($record); - } - - return $this->printFromThrowable($record, $exception); - } - - protected function printFromThrowable(array $record, \Throwable $throwable) - { - $record = $this->normalize($record); + $record = parent::format($record); $result = sprintf( "[%s] %s.%s: %s\n\n",