context; $changed = false; array_walk_recursive($context, function (&$item) use (&$changed) { if (is_a($item, Throwable::class)) { $item = $this->processException($item); $changed = true; } }); if ($changed) { $new_record = new LogRecord( $record->datetime, $record->channel, $record->level, $record->message, $context, $record->extra ); $record = $new_record; } if (is_a($record->message, Throwable::class)) { $exception = $record->message; $output = $this->processException($exception); $message = $output['message']; if (array_key_exists('exception', $context)) { $context['other_exception'] = $context['exception']; } $context['exception'] = $output; $new_record = new LogRecord( $record->datetime, $record->channel, $record->level, $message, $context, $record->extra ); $record = $new_record; } return $record; } protected function processException(Throwable $exception): array { $output = [ 'class' => get_class($exception), 'code' => $exception->getCode(), 'message' => $exception->getMessage(), 'file' => $exception->getFile(), 'line' => $exception->getLine(), 'trace' => $exception->getTraceAsString(), ]; if ($exception->getPrevious() !== null) { $output['previous'] = $this->processException($exception); } return $output; } }