From d0d539e6bae1d5b333828ad346eadef3399f5fb1 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Gerg=C5=91=20Tisza?= Date: Sun, 24 May 2015 11:30:10 +0000 Subject: [PATCH] Add a hook for reporting exceptions Bug: T100141 Change-Id: I893f8b93e09f9ef70beef46922d304fdb3600b78 --- RELEASE-NOTES-1.26 | 1 + docs/hooks.txt | 5 +++++ includes/exception/MWExceptionHandler.php | 7 ++++++- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/RELEASE-NOTES-1.26 b/RELEASE-NOTES-1.26 index af9e9d2b64..d1458bd399 100644 --- a/RELEASE-NOTES-1.26 +++ b/RELEASE-NOTES-1.26 @@ -15,6 +15,7 @@ production. "tag-" 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 ==== diff --git a/docs/hooks.txt b/docs/hooks.txt index 131986a7a6..8e9223b578 100644 --- a/docs/hooks.txt +++ b/docs/hooks.txt @@ -1842,6 +1842,11 @@ $param: Associative Array with the following additional options: "<div ...>$1</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 diff --git a/includes/exception/MWExceptionHandler.php b/includes/exception/MWExceptionHandler.php index c50b6c8c2b..a58705f64e 100644 --- a/includes/exception/MWExceptionHandler.php +++ b/includes/exception/MWExceptionHandler.php @@ -486,6 +486,8 @@ TXT; 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). - 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() ); @@ -515,5 +518,7 @@ TXT; if ( $json !== false ) { wfDebugLog( "$channel-json", $json, 'private' ); } + + Hooks::run( 'LogException', array( $e, $suppressed ) ); } } -- 2.20.1