diff options
Diffstat (limited to 'src/lib/error.handler.inc.php')
-rw-r--r-- | src/lib/error.handler.inc.php | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/src/lib/error.handler.inc.php b/src/lib/error.handler.inc.php new file mode 100644 index 0000000..9518e4b --- /dev/null +++ b/src/lib/error.handler.inc.php @@ -0,0 +1,44 @@ +<?php + +function initTheDevStackErrorHandler($logfile) { + // Save the log file name to constant for the error handler + define("LOGFILE", $logfile); + // Custom error handler that writes to a file + set_error_handler("theDevStackErrorHandler"); +} + +/** + * Error handler to write all messages to a dedicated log file. + */ +function theDevStackErrorHandler($errno, $errstr, $errfile, $errline) { + if (!(error_reporting() & $errno)) { + // This error code is not included in error_reporting + return; + } + $date = date(DATE_W3C); + $str = "$date "; + + switch ($errno) { + case E_USER_ERROR: + $str .= "ERROR [$errno]: $errstr, Fatal error on line $errline in file $errfile\n"; + break; + + case E_USER_WARNING: + $str .= "WARNING [$errno]: $errstr\n"; + break; + + case E_USER_NOTICE: + $str .= "NOTICE [$errno]: $errstr\n"; + break; + + default: + $str .= "Unknown error type: [$errno] $errstr\n"; + break; + } + + file_put_contents(LOGFILE, $str, FILE_APPEND); + + /* Don't execute PHP internal error handler */ + return true; +} +?>
\ No newline at end of file |