mirror of
https://github.com/Seldaek/monolog.git
synced 2025-10-25 02:26:16 +02:00
Handle __toString to serialize objects which are not json-serializable in JsonFormatter, fixes #1733
This commit is contained in:
@@ -178,12 +178,25 @@ class JsonFormatter extends NormalizerFormatter
|
||||
return $normalized;
|
||||
}
|
||||
|
||||
if ($data instanceof \DateTimeInterface) {
|
||||
return $this->formatDate($data);
|
||||
}
|
||||
if (is_object($data)) {
|
||||
if ($data instanceof \DateTimeInterface) {
|
||||
return $this->formatDate($data);
|
||||
}
|
||||
|
||||
if ($data instanceof Throwable) {
|
||||
return $this->normalizeException($data, $depth);
|
||||
if ($data instanceof Throwable) {
|
||||
return $this->normalizeException($data, $depth);
|
||||
}
|
||||
|
||||
// if the object has specific json serializability we want to make sure we skip the __toString treatment below
|
||||
if ($data instanceof \JsonSerializable) {
|
||||
return $data;
|
||||
}
|
||||
|
||||
if (method_exists($data, '__toString')) {
|
||||
return $data->__toString();
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
if (is_resource($data)) {
|
||||
|
||||
Reference in New Issue
Block a user