-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8bab14c
commit 0daa858
Showing
1 changed file
with
32 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
namespace Athos\Foundation; | ||
|
||
/** | ||
* Logger | ||
* Log REST requests and responses | ||
* | ||
* @package athos-foundation | ||
* @author Jannis Nikoy <[email protected]> | ||
* @license MIT | ||
* @link https://github.com/jannisnikoy/athos-foundation | ||
*/ | ||
|
||
class Logger { | ||
/** | ||
* Log data to exm_logs and print output in JSON | ||
* | ||
* @param int $statusCode HTTP status code | ||
* @param mixed $response Optional response payload | ||
*/ | ||
public static function printOutput($statusCode, $response) { | ||
global $db; | ||
|
||
http_response_code($statusCode); | ||
if(isset($response)) { | ||
echo json_encode($response, isset($_GET['prettify']) && $_GET['prettify'] == 'true' ? JSON_NUMERIC_CHECK | JSON_PRETTY_PRINT : JSON_NUMERIC_CHECK); | ||
} | ||
$db->query("INSERT INTO exm_logs(status_code, method, ipaddress, path, headers, request, response) VALUES(?, ?, ?, ?, ?, ?, ?)", $statusCode, $_SERVER['REQUEST_METHOD'], $_SERVER['REMOTE_ADDR'], $_SERVER['REQUEST_URI'], json_encode(getallheaders()), file_get_contents('php://input'), json_encode($response)); | ||
} | ||
} | ||
?> |