diff --git a/src/Loggers/BaseLogger.php b/src/Loggers/BaseLogger.php index 42aaf38..35c0b50 100644 --- a/src/Loggers/BaseLogger.php +++ b/src/Loggers/BaseLogger.php @@ -14,11 +14,14 @@ use HttpLog\Errors\ErrorHandler; abstract class BaseLogger { + /** @var Request $request The Request object to be logged. */ protected $request; + /** @var Request $request The Response object to be logged. */ protected $response; + /** @var string $log_filter The type of applied log filter. */ protected $log_filter; /** @var array $error Error data log. */ - protected $error = [ ]; + protected $errors = [ ]; /** * Create a base logger object. @@ -36,8 +39,11 @@ public function __construct($filter) { */ protected function create_log_models() { $filters = $this->process_filters(); - $this->request = new Request($filters["request_filters"]); - $this->response = new Response($filters["response_filters"]); + /* Check if the "only log errors" filter had been checked. */ + if ($filters !== "error") { + $this->request = new Request($filters["request_filters"]); + $this->response = new Response($filters["response_filters"]); + } } /** @@ -48,8 +54,12 @@ protected function create_log_models() { private function process_filters() { $request_filters = [ ]; $response_filters = [ ]; - /* Go through all proposed filters and sort them. */ $filters = (new ParameterFilter($this->log_filter))->create_filters(); + /* Check if the "only log errors" filter had been checked. */ + if ($filters === "error") { + return "error"; + } + /* Go through all proposed filters and sort them. */ foreach ($filters as $filter) { /* Check for non-existing filters*/ if (!property_exists(Request::class, $filter) && !property_exists(Response::class, $filter)) { @@ -77,7 +87,7 @@ private function process_filters() { * @return void */ public function store_error($error_data) { - $this->error[ ] = $error_data; + $this->errors[ ] = $error_data; } /**