Add a hook for reporting exceptions
authorGergő Tisza <gtisza@wikimedia.org>
Sun, 24 May 2015 11:30:10 +0000 (11:30 +0000)
committerBryanDavis <bdavis@wikimedia.org>
Wed, 3 Jun 2015 05:09:41 +0000 (05:09 +0000)
Bug: T100141
Change-Id: I893f8b93e09f9ef70beef46922d304fdb3600b78

RELEASE-NOTES-1.26
docs/hooks.txt
includes/exception/MWExceptionHandler.php

index af9e9d2..d1458bd 100644 (file)
@@ -15,6 +15,7 @@ production.
   "tag-<id>" interface message.
 * ':' (colon) is now invalid in usernames for new accounts. Existing accounts
   are not affected.
   "tag-<id>" interface message.
 * ':' (colon) is now invalid in usernames for new accounts. Existing accounts
   are not affected.
+* Added a new hook, 'LogException', to log exceptions in nonstandard ways.
 
 ==== External libraries ====
 
 
 ==== External libraries ====
 
index 131986a..8e9223b 100644 (file)
@@ -1842,6 +1842,11 @@ $param: Associative Array with the following additional options:
     "&lt;div ...>$1&lt;/div>").
   - flags Integer display flags (NO_ACTION_LINK,NO_EXTRA_USER_LINKS)
 
     "&lt;div ...>$1&lt;/div>").
   - flags Integer display flags (NO_ACTION_LINK,NO_EXTRA_USER_LINKS)
 
+'LogException': Called before an exception (or PHP error) is logged. This is meant for integration
+with external error aggregation services; returning false will NOT prevent logging.
+$e: The exception (in case of a plain old PHP error, a wrapping ErrorException)
+$suppressed: true if the error was suppressed via error_reporting()/wfSuppressWarnings()
+
 'LoginAuthenticateAudit': A login attempt for a valid user account either
 succeeded or failed. No return data is accepted; this hook is for auditing only.
 $user: the User object being authenticated against
 'LoginAuthenticateAudit': A login attempt for a valid user account either
 succeeded or failed. No return data is accepted; this hook is for auditing only.
 $user: the User object being authenticated against
index c50b6c8..a58705f 100644 (file)
@@ -486,6 +486,8 @@ TXT;
                        if ( $json !== false ) {
                                wfDebugLog( 'exception-json', $json, 'private' );
                        }
                        if ( $json !== false ) {
                                wfDebugLog( 'exception-json', $json, 'private' );
                        }
+
+                       Hooks::run( 'LogException', array( $e, false ) );
                }
        }
 
                }
        }
 
@@ -501,7 +503,8 @@ TXT;
 
                // The set_error_handler callback is independent from error_reporting.
                // Filter out unwanted errors manually (e.g. when wfSuppressWarnings is active).
 
                // The set_error_handler callback is independent from error_reporting.
                // Filter out unwanted errors manually (e.g. when wfSuppressWarnings is active).
-               if ( ( error_reporting() & $e->getSeverity() ) !== 0 ) {
+               $suppressed = ( error_reporting() & $e->getSeverity() ) === 0;
+               if ( !$suppressed ) {
                        $log = self::getLogMessage( $e );
                        if ( $wgLogExceptionBacktrace ) {
                                wfDebugLog( $channel, $log . "\n" . $e->getTraceAsString() );
                        $log = self::getLogMessage( $e );
                        if ( $wgLogExceptionBacktrace ) {
                                wfDebugLog( $channel, $log . "\n" . $e->getTraceAsString() );
@@ -515,5 +518,7 @@ TXT;
                if ( $json !== false ) {
                        wfDebugLog( "$channel-json", $json, 'private' );
                }
                if ( $json !== false ) {
                        wfDebugLog( "$channel-json", $json, 'private' );
                }
+
+               Hooks::run( 'LogException', array( $e, $suppressed ) );
        }
 }
        }
 }