From 7e292813bc460f952868230ede45f2417f3ed439 Mon Sep 17 00:00:00 2001 From: Mayank Agarwal Date: Fri, 16 May 2025 15:40:59 +0530 Subject: [PATCH] Truncate logs in function worker --- src/Appwrite/Platform/Workers/Functions.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/Appwrite/Platform/Workers/Functions.php b/src/Appwrite/Platform/Workers/Functions.php index 2e25248d9a..ea30a0b8ff 100644 --- a/src/Appwrite/Platform/Workers/Functions.php +++ b/src/Appwrite/Platform/Workers/Functions.php @@ -549,15 +549,25 @@ class Functions extends Action $headersFiltered[] = [ 'name' => $key, 'value' => $value ]; } } + + $maxLogLength = 100000; + $logs = $executionResponse['logs'] ?? ''; + $logsTruncated = false; + + if (\is_string($logs) && \strlen($logs) > $maxLogLength) { + $logs = \substr($logs, 0, $maxLogLength) . "\n[WARNING] Logs truncated. The output exceeded {$maxLogLength} characters."; + $logsTruncated = true; + } /** Update execution status */ $execution ->setAttribute('status', $status) ->setAttribute('responseStatusCode', $executionResponse['statusCode']) ->setAttribute('responseHeaders', $headersFiltered) - ->setAttribute('logs', $executionResponse['logs']) - ->setAttribute('errors', $executionResponse['errors']) + ->setAttribute('logs', $logs) + ->setAttribute('errors', $executionResponse['errors'] . ($logsTruncated ? "\n[WARNING] Logs were truncated." : '')) ->setAttribute('duration', $executionResponse['duration']); + } catch (\Throwable $th) { $durationEnd = \microtime(true); $execution