Better logging

This commit is contained in:
Conner Harkness 2025-09-02 07:45:32 -06:00
parent 664db2fb7c
commit fe40f99ebd
2 changed files with 15 additions and 16 deletions

View File

@ -1,6 +1,16 @@
<?php
ini_set("display_errors", "off");
// Logging must be defined early on:
class Framework
{
public static function log()
{
$strText = implode(" ", func_get_args());
error_log("INFO: {$strText}");
}
}
// For compatibility with PHP 5.3.0:
$varConstants = array(
array("JSON_HEX_TAG", 1),
@ -80,6 +90,7 @@
if ($intValid)
{
Framework::log("Sending file {$strTargetFilePath}");
ob_clean();
echo file_get_contents($strTargetFilePath);
ob_end_flush();
@ -114,7 +125,10 @@
$strLibraryFilePath = "{$strLibraryDirPath}/{$strLibraryFileName}";
if (preg_match("/\.php$/", $strLibraryFilePath))
if (is_file($strLibraryFilePath))
{
Framework::log("Requiring library {$strLibraryFilePath}");
require $strLibraryFilePath;
}
}
$strBodyTagAttributes = "";
@ -126,7 +140,7 @@
{
if (is_file($strScript))
{
error_log($strScript);
Framework::log("Requiring {$strScript}");
require $strScript;
}
}

View File

@ -15,8 +15,6 @@
if ($strParam == null)
$strParam = "";
error_log("INFO: " . json_encode($_SERVER, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
foreach (["REQUEST_URI", "PATH_INFO"] as $k)
if (strlen($strParam) < 1)
{
@ -37,8 +35,6 @@
$strParam = $_SERVER["PATH_INFO"];
}
//error_log(json_encode($_SERVER, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
$strPath = $strParam;
$strPath = preg_replace("/^\//", "", $strPath);
$strPath = preg_replace("/\/$/", "", $strPath);
@ -92,8 +88,6 @@
array_shift($varArgs);
error_log($strParam);
Request::$varArgs = $varArgs;
Request::$strResourcePath = $strPath;
}
@ -217,18 +211,9 @@
return null;
}
public static function log()
{
//$strPath = $_SERVER["PATH_INFO"];
error_log("[{$strPath}] INFO: " . implode(" ", func_get_args()));
}
}
// Call this no matter what to understand the request:
Request::process();
Request::processExtra();
Request::log("");
?>