Skip to content

Commit

Permalink
Added the handling for the 'error' filter & wrote additional comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
Aldin-SXR committed Mar 11, 2019
1 parent 9f84be3 commit f69bdde
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions src/Loggers/BaseLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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"]);
}
}

/**
Expand All @@ -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)) {
Expand Down Expand Up @@ -77,7 87,7 @@ private function process_filters() {
* @return void
*/
public function store_error($error_data) {
$this->error[ ] = $error_data;
$this->errors[ ] = $error_data;
}

/**
Expand Down

0 comments on commit f69bdde

Please sign in to comment.