-
Notifications
You must be signed in to change notification settings - Fork 0
/
_errorHandler.php
40 lines (35 loc) · 1.16 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
<?php
function errorHandler( $errorLevel, $message, $sourceFile, $lineNumber ) {
$logFile = getLogFile();
$logInfo = "----------\n"
. "Error level: $errorLevel\n"
. "Message: $message\n"
. "In file: $sourceFile\n"
. "In line: $lineNumber\n"
. "----------\n\n";
$logFile -> flock( LOCK_EX );
$logFile -> fwrite( $logInfo );
$logFile -> flock( LOCK_UN );
return false; //returns false, so PHP continues with it's internal error handling
}
function exceptionHandler( $exception ) {
$logFile = getLogFile();
$logInfo = "----------\n"
. "Uncaught exception: {$exception -> getMessage()}\n"
. "In file: {$exception -> getFile()}\n"
. "In line: {$exception -> getLine()}\n"
. "----------\n\n";
$logFile -> flock( LOCK_EX );
$logFile -> fwrite( $logInfo );
$logFile -> flock( LOCK_UN );
}
function getLogFile() {
if( !file_exists( '/tmp/rap-php.log' ) ) {
$handle = fopen( '/tmp/rap-php.log', 'w' );
fclose( $handle );
}
return new SplFileObject( '/tmp/rap-php.log', 'a' );
}
set_error_handler( 'errorHandler' );
set_exception_handler( 'exceptionHandler' );
?>