-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherror_handler.php
34 lines (30 loc) · 996 Bytes
/
error_handler.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
<?php
if (!defined('ENTRYPOINT')) die("Cannot Be Called Directly\n");
if(!defined('DEBUG')) define('DEBUG', false); // For verbose output, set this to true
/**
* ErrorHandler Class
* This is a simple error handler
* It's a static that you simply call ErrorHandler::raise($message) to log and display an error message
* with an options break to halt execution of the script
* @author adamc
*
*/
class ErrorHandler{
public static $log_file = 'error.log';
/**
* raise Static Method
* raise an error, echo error message and output to the error log
* die if break==true
* @param string $message
* @param bool $break
*/
public static function raise($message, $break = false){
if(DEBUG) echo "{$message}\n";
$message = "[".date('Y-m-d H:i:s')."] {$message}\n";
if(file_put_contents(self::$log_file, $message, FILE_APPEND) === false){
echo "!* Failed to Write Error to Log [".self::$log_file."]\n";
}
if($break) die();
}
}
?>