Skip to content

Commit 7e7fce8

Browse files
committed
move data to front of error log
1 parent a7d4d26 commit 7e7fce8

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

resources/lib/UnityHTTPD.php

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,17 @@ public static function errorLog(
4343
error_log("$title: $message");
4444
return;
4545
}
46-
$output = [
47-
"message" => $message,
48-
"REMOTE_USER" => $_SERVER["REMOTE_USER"] ?? null,
49-
"REMOTE_ADDR" => $_SERVER["REMOTE_ADDR"] ?? null,
50-
];
46+
$output = ["message" => $message];
47+
if (!is_null($data)) {
48+
try {
49+
\jsonEncode($data);
50+
$output["data"] = $data;
51+
} catch (\JsonException $e) {
52+
$output["data"] = "data could not be JSON encoded: " . $e->getMessage();
53+
}
54+
}
55+
$output["REMOTE_USER"] = $_SERVER["REMOTE_USER"] ?? null;
56+
$output["REMOTE_ADDR"] = $_SERVER["REMOTE_ADDR"] ?? null;
5157
if (!is_null($errorid)) {
5258
$output["errorid"] = $errorid;
5359
}
@@ -57,14 +63,6 @@ public static function errorLog(
5763
// newlines are bad for error log, but getTrace() is too verbose
5864
$output["trace"] = explode("\n", (new \Exception())->getTraceAsString());
5965
}
60-
if (!is_null($data)) {
61-
try {
62-
\jsonEncode($data);
63-
$output["data"] = $data;
64-
} catch (\JsonException $e) {
65-
$output["data"] = "data could not be JSON encoded: " . $e->getMessage();
66-
}
67-
}
6866
error_log("$title: " . \jsonEncode($output));
6967
}
7068

0 commit comments

Comments
 (0)