diff --git a/src/Monolog/Formatter/JsonFormatter.php b/src/Monolog/Formatter/JsonFormatter.php index bd82f1df..06e9d13d 100644 --- a/src/Monolog/Formatter/JsonFormatter.php +++ b/src/Monolog/Formatter/JsonFormatter.php @@ -163,12 +163,17 @@ class JsonFormatter extends NormalizerFormatter * Normalizes given exception with or without its own stack trace based on * `includeStacktraces` property. * - * @param Exception $e + * @param Exception|Throwable $e * * @return array */ - protected function normalizeException(Exception $e) + protected function normalizeException($e) { + // TODO 2.0 only check for Throwable + if (!$e instanceof Exception && !$e instanceof \Throwable) { + throw new \InvalidArgumentException('Exception/Throwable expected, got '.gettype($e).' / '.get_class($e)); + } + $data = array( 'class' => get_class($e), 'message' => $e->getMessage(), diff --git a/src/Monolog/Formatter/LineFormatter.php b/src/Monolog/Formatter/LineFormatter.php index 388e2266..f74dacd1 100644 --- a/src/Monolog/Formatter/LineFormatter.php +++ b/src/Monolog/Formatter/LineFormatter.php @@ -11,8 +11,6 @@ namespace Monolog\Formatter; -use Exception; - /** * Formats incoming records into a one-line string * @@ -114,8 +112,13 @@ class LineFormatter extends NormalizerFormatter return $this->replaceNewlines($this->convertToString($value)); } - protected function normalizeException(Exception $e) + protected function normalizeException($e) { + // TODO 2.0 only check for Throwable + if (!$e instanceof \Exception && !$e instanceof \Throwable) { + throw new \InvalidArgumentException('Exception/Throwable expected, got '.gettype($e).' / '.get_class($e)); + } + $previousText = ''; if ($previous = $e->getPrevious()) { do { diff --git a/src/Monolog/Formatter/NormalizerFormatter.php b/src/Monolog/Formatter/NormalizerFormatter.php index 67f4b720..a76e2aed 100644 --- a/src/Monolog/Formatter/NormalizerFormatter.php +++ b/src/Monolog/Formatter/NormalizerFormatter.php @@ -90,7 +90,8 @@ class NormalizerFormatter implements FormatterInterface } if (is_object($data)) { - if ($data instanceof Exception) { + // TODO 2.0 only check for Throwable + if ($data instanceof Exception || (PHP_VERSION_ID > 70000 && $data instanceof \Throwable)) { return $this->normalizeException($data); } @@ -112,8 +113,13 @@ class NormalizerFormatter implements FormatterInterface return '[unknown('.gettype($data).')]'; } - protected function normalizeException(Exception $e) + protected function normalizeException($e) { + // TODO 2.0 only check for Throwable + if (!$e instanceof Exception && !$e instanceof \Throwable) { + throw new \InvalidArgumentException('Exception/Throwable expected, got '.gettype($e).' / '.get_class($e)); + } + $data = array( 'class' => get_class($e), 'message' => $e->getMessage(),