enablig api logging

This commit is contained in:
Fernando Ontiveros
2025-04-22 17:39:18 +00:00
parent 7093cab058
commit ef0f2d4bb8
7 changed files with 22 additions and 18 deletions

View File

@@ -224,6 +224,8 @@ class WebApplication
*/
public function dispatchApiRequest($uri, $version = "1.0", $multipart = false, $inputExecute = '')
{
$startingTime = microtime(true);
$uri = $this->initRest($uri, "1.0", $multipart);
// to handle a request with "OPTIONS" method
@@ -242,12 +244,20 @@ class WebApplication
* that automatically is sent by a client using XmlHttpRequest or similar.
*/
header('Access-Control-Allow-Origin: *');
$_SERVER['REQUEST_URI'] = $uri;
$this->rest->inputExecute = $inputExecute;
$this->rest->handle();
$serverAddr = $_SERVER ['SERVER_ADDR'];
$endTime = microtime(true);
$time = $endTime - $startingTime;
Bootstrap::verifyPath(PATH_DATA . 'logs', true);
$fpt = fopen(PATH_DATA . 'logs/api.log', 'a');
fwrite($fpt, sprintf("%s %7.6f %-15s %-4s %s\n", date('Y-m-d H:i:s'), $time, getenv('REMOTE_ADDR'), $_SERVER ['REQUEST_METHOD'], $_SERVER ['REQUEST_URI']));
fclose($fpt);
if ($this->rest->flagMultipart === true) {
return $this->rest->responseMultipart;
}