mirror of
https://github.com/Seldaek/monolog.git
synced 2025-08-08 06:06:40 +02:00
PHP7 compat for exception classes, fixes #718
This commit is contained in:
@@ -163,12 +163,17 @@ class JsonFormatter extends NormalizerFormatter
|
|||||||
* Normalizes given exception with or without its own stack trace based on
|
* Normalizes given exception with or without its own stack trace based on
|
||||||
* `includeStacktraces` property.
|
* `includeStacktraces` property.
|
||||||
*
|
*
|
||||||
* @param Exception $e
|
* @param Exception|Throwable $e
|
||||||
*
|
*
|
||||||
* @return array
|
* @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(
|
$data = array(
|
||||||
'class' => get_class($e),
|
'class' => get_class($e),
|
||||||
'message' => $e->getMessage(),
|
'message' => $e->getMessage(),
|
||||||
|
@@ -11,8 +11,6 @@
|
|||||||
|
|
||||||
namespace Monolog\Formatter;
|
namespace Monolog\Formatter;
|
||||||
|
|
||||||
use Exception;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Formats incoming records into a one-line string
|
* Formats incoming records into a one-line string
|
||||||
*
|
*
|
||||||
@@ -114,8 +112,13 @@ class LineFormatter extends NormalizerFormatter
|
|||||||
return $this->replaceNewlines($this->convertToString($value));
|
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 = '';
|
$previousText = '';
|
||||||
if ($previous = $e->getPrevious()) {
|
if ($previous = $e->getPrevious()) {
|
||||||
do {
|
do {
|
||||||
|
@@ -90,7 +90,8 @@ class NormalizerFormatter implements FormatterInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (is_object($data)) {
|
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);
|
return $this->normalizeException($data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -112,8 +113,13 @@ class NormalizerFormatter implements FormatterInterface
|
|||||||
return '[unknown('.gettype($data).')]';
|
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(
|
$data = array(
|
||||||
'class' => get_class($e),
|
'class' => get_class($e),
|
||||||
'message' => $e->getMessage(),
|
'message' => $e->getMessage(),
|
||||||
|
Reference in New Issue
Block a user