Skip to content

Commit

Permalink
Merge pull request #102 from open-runtimes/chore-logging-structure
Browse files Browse the repository at this point in the history
Chores: Update logging structure
  • Loading branch information
christyjacob4 authored Sep 12, 2024
2 parents c6077f4 + 7bab66d commit 88f3ded
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
24 changes: 17 additions & 7 deletions app/http.php
Original file line number Diff line number Diff line change
Expand Up @@ -1367,6 +1367,12 @@ function (string $runtimeId, ?string $payload, string $path, string $method, mix
->action(function (?Route $route, Throwable $error, ?Logger $logger, Response $response, Log $log) {
logError($log, $error, "httpError", $logger, $route);

$version = System::getEnv('OPR_EXECUTOR_VERSION', 'UNKNOWN');
$message = $error->getMessage();
$file = $error->getFile();
$line = $error->getLine();
$trace = $error->getTrace();

switch ($error->getCode()) {
case 400: // Error allowed publicly
case 401: // Error allowed publicly
Expand All @@ -1386,13 +1392,17 @@ function (string $runtimeId, ?string $payload, string $path, string $method, mix
$code = 500; // All other errors get the generic 500 server error status code
}

$output = [
'message' => $error->getMessage(),
'code' => $error->getCode(),
'file' => $error->getFile(),
'line' => $error->getLine(),
'trace' => $error->getTrace(),
'version' => Http::getEnv('OPR_EXECUTOR_VERSION', 'UNKNOWN')
$output = ((Http::isDevelopment())) ? [
'message' => $message,
'code' => $code,
'file' => $file,
'line' => $line,
'trace' => \json_encode($trace, JSON_UNESCAPED_UNICODE) === false ? [] : $trace, // check for failing encode
'version' => $version
] : [
'message' => $message,
'code' => $code,
'version' => $version
];

$response
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"utopia-php/framework": "0.34.*",
"utopia-php/logger": "0.6.*",
"utopia-php/cli": "0.16.*",
"utopia-php/storage": "0.18.*",
"utopia-php/storage": "0.18.4",
"utopia-php/dsn": "0.1.*",
"utopia-php/registry": "0.5.*",
"utopia-php/preloader": "0.2.*",
Expand Down
2 changes: 1 addition & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 88f3ded

Please sign in to comment.