exception: Improve formatting of fatal error log messages
Use human-readable stack trace instead of array dump, try to display the URL and the request ID, use the same message format as exceptions, Bug: T189851 Change-Id: I3edf2dbd5639ceecc668719c065ecdce33157ff5
This commit is contained in:
parent
3577973107
commit
8ee55867c6
2 changed files with 18 additions and 4 deletions
|
|
@ -270,6 +270,8 @@ class WebRequest {
|
|||
* @since 1.27
|
||||
*/
|
||||
public static function getRequestId() {
|
||||
// This method is called from various error handlers and should be kept simple.
|
||||
|
||||
if ( !self::$reqId ) {
|
||||
self::$reqId = isset( $_SERVER['UNIQUE_ID'] )
|
||||
? $_SERVER['UNIQUE_ID'] : wfRandomString( 24 );
|
||||
|
|
@ -781,6 +783,8 @@ class WebRequest {
|
|||
* @return string
|
||||
*/
|
||||
public static function getGlobalRequestURL() {
|
||||
// This method is called on fatal errors; it should not depend on anything complex.
|
||||
|
||||
if ( isset( $_SERVER['REQUEST_URI'] ) && strlen( $_SERVER['REQUEST_URI'] ) ) {
|
||||
$base = $_SERVER['REQUEST_URI'];
|
||||
} elseif ( isset( $_SERVER['HTTP_X_ORIGINAL_URL'] )
|
||||
|
|
|
|||
|
|
@ -276,12 +276,21 @@ class MWExceptionHandler {
|
|||
return false;
|
||||
}
|
||||
|
||||
$msg = "[{exception_id}] PHP Fatal Error: {$message}";
|
||||
$url = WebRequest::getGlobalRequestURL();
|
||||
$msgParts = [
|
||||
'[{exception_id}] {exception_url} PHP Fatal Error',
|
||||
( $line || $file ) ? ' from' : '',
|
||||
$line ? " line $line" : '',
|
||||
( $line && $file ) ? ' of' : '',
|
||||
$file ? " $file" : '',
|
||||
": $message",
|
||||
];
|
||||
$msg = implode( '', $msgParts );
|
||||
|
||||
// Look at message to see if this is a class not found failure
|
||||
// HHVM: Class undefined: foo
|
||||
// PHP5: Class 'foo' not found
|
||||
if ( preg_match( "/Class (undefined: \w+|'\w+' not found)/", $msg ) ) {
|
||||
if ( preg_match( "/Class (undefined: \w+|'\w+' not found)/", $message ) ) {
|
||||
// phpcs:disable Generic.Files.LineLength
|
||||
$msg = <<<TXT
|
||||
{$msg}
|
||||
|
|
@ -308,9 +317,10 @@ TXT;
|
|||
'code' => $level,
|
||||
'file' => $file,
|
||||
'line' => $line,
|
||||
'trace' => static::redactTrace( $trace ),
|
||||
'trace' => self::prettyPrintTrace( self::redactTrace( $trace ) ),
|
||||
],
|
||||
'exception_id' => wfRandomString( 8 ),
|
||||
'exception_id' => WebRequest::getRequestId(),
|
||||
'exception_url' => $url,
|
||||
'caught_by' => self::CAUGHT_BY_HANDLER
|
||||
] );
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue