-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherrorHandler.php
43 lines (31 loc) · 1.25 KB
/
errorHandler.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<?php
declare(strict_types=1);
use Cassandra\Date;
$errors = ["errno" => "", "errstr" => "", "errfile" => "", "errline" => ""];
error_reporting(E_ALL);
ini_set("display_errors", "0");
/*
* log echo to error_log.txt
*/
function standardErrorHandler($errno, $errstr, $errfile, $errline): void
{
$message = "Error: [$errno] $errstr - $errfile:$errline";
error_log($message . PHP_EOL, 3, "error_log.txt");
}
function jsonErrorHandler($errno, $errstr, $errfile, $errline) : void{
// $current_date = new Date('Y-m-d H:i:s');
// $errors["date"] = $current_date;
$errors["errno"] = $errno;
$errors["errstr"] = $errstr;
$errors["errfile"] = $errfile;
$errors["errline"] = $errline;
error_log(json_encode($errors, JSON_PRETTY_PRINT) . PHP_EOL, 3, "error_log.txt");
}
function var_obj_log($object=null ) : void{
ob_start(); // start buffer capture
var_dump( $object ); // dump the values
$contents = ob_get_contents(); // put the buffer into a variable
ob_end_clean(); // end capture
error_log( $contents . PHP_EOL, 3, "error_log.txt"); // log contents of the result of var_dump( $object )
}
set_error_handler("jsonErrorHandler");