Skip to content

Commit

Permalink
Update Logger.php
Browse files Browse the repository at this point in the history
  • Loading branch information
jannisnikoy committed Mar 31, 2024
1 parent 5ccd7c1 commit 1cfd2d5
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/Logger.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class Logger {
* @param int $statusCode HTTP status code
* @param mixed $response Optional response payload
*/
public static function printOutput(int $statusCode, mixed $response = null): void {
public static function printOutput(int $statusCode, mixed $response = null, float $executionStartTime = null): void {
global $db;

http_response_code($statusCode);
Expand All @@ -42,8 +42,14 @@ public static function printOutput(int $statusCode, mixed $response = null): voi
echo $responseJson;
}

$executionTime = null;

if(isset($executionStartTime)) {
$executionTime = microtime(true) - $executionStartTime;
}

try {
$db->query("INSERT INTO exm_logs(status_code, method, user_agent, ipaddress, path, headers, request, response) VALUES(?, ?, ?, ?, ?, ?, ?, ?)", $statusCode, $_SERVER['REQUEST_METHOD'], $_SERVER['HTTP_USER_AGENT'], $_SERVER['REMOTE_ADDR'], $_SERVER['REQUEST_URI'], json_encode(getallheaders()), file_get_contents('php://input'), json_encode($response));
$db->query("INSERT INTO exm_logs(status_code, method, user_agent, ipaddress, path, headers, request, response, execution_time) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?)", $statusCode, $_SERVER['REQUEST_METHOD'], $_SERVER['HTTP_USER_AGENT'], $_SERVER['REMOTE_ADDR'], $_SERVER['REQUEST_URI'], json_encode(getallheaders()), file_get_contents('php://input'), json_encode($response), $executionTime);
} catch (Exception $e) {

}
Expand Down

0 comments on commit 1cfd2d5

Please sign in to comment.