Skip to content

mansartesteban/error-handler

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Language

Français

Presentation

This libs make you ablde to handle Exceptions. It create log files sorted by date and type. ErrorHandler provide a parsing system for log file to display beautiful interface (Inprogress)

Documentation

Methods

ErrorHandler::init($options = []);
ErrorHandler::isCreated();
ErrorHandler::log($type = "", Exception $ex, mixed $additionalParameters = null);

Options

ErrorHandler::init($options = []);

At initialization, you have to pass as parameter an options array to define the behavior of you handler, otherwise it will throw a LogicException

$options = [
  "logDir" => "/log", // Path to directory which contains log files
  "cssClass" => "errorHandler-log", // CSS class name that delimitate a log section
];

logDir is a string you define. If it ends by "/", the "/" will be ignored (Ex: "/private/log", "/log", "/engine/error/log/", ...)

cssClass is stringyou define (Ex: "log", "error-log", "admin-log-section", ...)


ErrorHandler::log($type = "", Exception $ex, $additionalParameters = null)

type is a string which define the error type. It is used to create sub-diirectory in $options["logDir"] (Ex: "PDO", "PHP", "API_FACEBOOK", ...)

ex is an Exception that you catch or instanciate. You can pass any Exception type herited.

Examples

Initialization

//File : /src/config/initClasses.php

$optionsErrorHandler = [
  "logDir" => "/private/log",
  "cssClass" => "log-error"
];

if (!ErrorHandler::isCreated()) {
  ErrorHandler::init($optionsErrorHandler);
}

Log an Exception

// Exemple 1 :
try {
  // your code here ...
} catch (PDOException $ex) {
  ErrorHandler::log("PDO", $ex, [$sqlReq, $sqlParams]);
}

// Exemple 2 :
if ($url == null) {
  ErrorHandler::log("logic", new LogicExepction("url for cURL request is null"));
}

Releases

No releases published

Packages

No packages published

Languages