From b20c45df10137927a031de4e27a0228e945c09f3 Mon Sep 17 00:00:00 2001 From: Brett McBride Date: Tue, 6 Feb 2024 12:32:25 +1100 Subject: [PATCH] log previous exception message from error writer (#1231) it's not always clear from an exception message what the underlying issue was, so also print out the previous exception's message, if available. --- src/API/Behavior/Internal/LogWriter/Formatter.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/API/Behavior/Internal/LogWriter/Formatter.php b/src/API/Behavior/Internal/LogWriter/Formatter.php index 4cfd6f9d4..2677662b9 100644 --- a/src/API/Behavior/Internal/LogWriter/Formatter.php +++ b/src/API/Behavior/Internal/LogWriter/Formatter.php @@ -12,11 +12,13 @@ public static function format($level, string $message, array $context): string ? $context['exception'] : null; if ($exception) { + $previous = $exception->getPrevious() ? $exception->getPrevious()->getMessage() : ''; $message = sprintf( - 'OpenTelemetry: [%s] %s [exception] %s%s%s', + 'OpenTelemetry: [%s] %s [exception] %s [previous] %s%s%s', $level, $message, $exception->getMessage(), + $previous, PHP_EOL, $exception->getTraceAsString() );