twocoffeecups/php-error-handler

A simple and easy php error handler.

0.0.1 2024-10-07 20:37 UTC

This package is auto-updated.

Last update: 2025-07-07 22:20:37 UTC


README

An easy-to-use PHP error handler that helps with code debugging and allows you to save logs.

Screenshot 2024-10-07 231526

Installation

Use this command:

composer require twocoffeecups/php-error-handler

Usage

Add the class \TwoCoffeCups\PHPErrorHandler\ErrorHandler() to the beginning of your index file:

<?php

require_once "../vendor/autoload.php";

// new ErrorHandler object
new \TwoCoffeCups\PHPErrorHandler\ErrorHandler();

// your code:
...

Log files

You can save the error log to a file by adding two optional parameters to the class declaration.

  • $saveLog: By default, it takes the value is false. To enable saving logs, set the value - true.
  • $pathToLogFile: By default, it takes the value is null. Add a string variable with the path to the folder containing the log file.

Usage example:

$saveLog = true;

// path to logs dir
$pathToLogFile = __DIR__ . "/logs";

// new ErrorHandler object
new \TwoCoffeCups\PHPErrorHandler\ErrorHandler(
    $saveLog,
    $pathToLogFile,
);

Debug

If you want to use the funds for debugging, add to the beginning of the script:

use TwoCoffeCups\PHPErrorHandler\Debugger\Debugger;

And use it in your code:

$str = "Some text";

// if you need the script not to shut down
Debugger::dump($str)

// if you need the script to shut down
Debugger::dd($str)

Known problems

  • If you have enabled the saving of log files and receive the "access error" message, please check that you have permission to write files to the specified folder.