-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added feature to log the request uri when fatal errors encountered. (#…
…324)
- Loading branch information
1 parent
0ce137e
commit 930ce50
Showing
2 changed files
with
39 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
/** | ||
* @file | ||
* | ||
* Adds a shutdown function that logs fatal errors along with the REQUEST_URI. | ||
* | ||
* Intention is to allow tracking of specific routes that exhaust memory limit. | ||
*/ | ||
|
||
/** | ||
* Returns a list of error types the custom error handler should respond to. | ||
*/ | ||
function bay_fatal_error_types() { | ||
return [ | ||
E_ERROR => 'E_ERROR', | ||
E_PARSE => 'E_PARSE', | ||
E_CORE_ERROR => 'E_CORE_ERROR', | ||
E_COMPILE_ERROR => 'E_COMPILE_ERROR', | ||
]; | ||
} | ||
|
||
register_shutdown_function(function() { | ||
$error = error_get_last(); | ||
$types = bay_fatal_error_types(); | ||
if ($error && in_array($error['type'], array_keys($types))) { | ||
$data = [ | ||
'type' => $types[$error['type']], | ||
'message' => $error['message'], | ||
'request_uri' => $_SERVER['REQUEST_URI'] ?: 'N/A', | ||
]; | ||
error_log("[BAY_FATAL] " . json_encode($data)); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters