From 7e7fce8f1e712ad82239e5552146c92a44d0a559 Mon Sep 17 00:00:00 2001 From: Simon Leary Date: Fri, 31 Oct 2025 18:14:01 -0400 Subject: [PATCH] move data to front of error log --- resources/lib/UnityHTTPD.php | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/resources/lib/UnityHTTPD.php b/resources/lib/UnityHTTPD.php index 542ce41d..df4948d7 100644 --- a/resources/lib/UnityHTTPD.php +++ b/resources/lib/UnityHTTPD.php @@ -43,11 +43,17 @@ public static function errorLog( error_log("$title: $message"); return; } - $output = [ - "message" => $message, - "REMOTE_USER" => $_SERVER["REMOTE_USER"] ?? null, - "REMOTE_ADDR" => $_SERVER["REMOTE_ADDR"] ?? null, - ]; + $output = ["message" => $message]; + if (!is_null($data)) { + try { + \jsonEncode($data); + $output["data"] = $data; + } catch (\JsonException $e) { + $output["data"] = "data could not be JSON encoded: " . $e->getMessage(); + } + } + $output["REMOTE_USER"] = $_SERVER["REMOTE_USER"] ?? null; + $output["REMOTE_ADDR"] = $_SERVER["REMOTE_ADDR"] ?? null; if (!is_null($errorid)) { $output["errorid"] = $errorid; } @@ -57,14 +63,6 @@ public static function errorLog( // newlines are bad for error log, but getTrace() is too verbose $output["trace"] = explode("\n", (new \Exception())->getTraceAsString()); } - if (!is_null($data)) { - try { - \jsonEncode($data); - $output["data"] = $data; - } catch (\JsonException $e) { - $output["data"] = "data could not be JSON encoded: " . $e->getMessage(); - } - } error_log("$title: " . \jsonEncode($output)); }