diff options
| author | winter | 2025-01-14 18:38:40 +0000 |
|---|---|---|
| committer | winter | 2025-01-14 18:38:40 +0000 |
| commit | 7e862e1bd62f1e1e25f6cec5cf740aa3d3a5b835 (patch) | |
| tree | 1bb2c49248458f3bd6106d5f8a3ec42bbf8dd358 /Digitigrade | |
| parent | eda5788d76ecb802fb174968a9ec1fb382670885 (diff) | |
add request logging to router
Diffstat (limited to 'Digitigrade')
| -rw-r--r-- | Digitigrade/GlobalConfig.php | 10 | ||||
| -rw-r--r-- | Digitigrade/Logger.php | 4 | ||||
| -rw-r--r-- | Digitigrade/Router.php | 1 |
3 files changed, 15 insertions, 0 deletions
diff --git a/Digitigrade/GlobalConfig.php b/Digitigrade/GlobalConfig.php index 7fbfab3..63a1031 100644 --- a/Digitigrade/GlobalConfig.php +++ b/Digitigrade/GlobalConfig.php @@ -28,6 +28,16 @@ class GlobalConfig extends Singleton { return $this->confData['debug']['send_tracebacks'] ?? false; } + public function getLogLevel(): int { + return match ($this->confData['debug']['log_level']) { + 'debug' => Logger::LEVEL_DEBUG, + 'info' => Logger::LEVEL_INFO, + 'warning' => Logger::LEVEL_WARNING, + 'error' => Logger::LEVEL_ERROR, + default => Logger::LEVEL_INFO + }; + } + public function getDbConnection(): string { return 'pgsql:host=' . $this->confData['database']['host'] . ';port=' . $this->confData['database']['port'] . diff --git a/Digitigrade/Logger.php b/Digitigrade/Logger.php index 2a87c21..b4f06b7 100644 --- a/Digitigrade/Logger.php +++ b/Digitigrade/Logger.php @@ -13,6 +13,10 @@ class Logger extends Singleton { private int $minLevel = self::LEVEL_INFO; + protected function __construct() { + $this->setMinimumLevel(GlobalConfig::getInstance()->getLogLevel()); + } + public function setMinimumLevel(int $level) { $this->minLevel = $level; diff --git a/Digitigrade/Router.php b/Digitigrade/Router.php index 0682b76..e51e124 100644 --- a/Digitigrade/Router.php +++ b/Digitigrade/Router.php @@ -30,6 +30,7 @@ class Router extends Singleton { $e->httpHeaders(); echo '<h1>' . $e->httpReason() . '</h1><pre>' . $e->getMessage() . '</pre>'; } + Logger::getInstance()->debug('Router: ' . http_response_code() . ' ' . $this->requestPath); } private function processRequestInner() { |
