Skip to content

Commit

Permalink
Normal PHP errors are also nicely formatted now
Browse files Browse the repository at this point in the history
  • Loading branch information
waltertamboer committed Jun 6, 2018
1 parent 325fd35 commit 848555e
Showing 1 changed file with 4 additions and 14 deletions.
18 changes: 4 additions & 14 deletions src/Formatter/HumanReadableExceptionFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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",
Expand Down

0 comments on commit 848555e

Please sign in to comment.