Krinkle has uploaded a new change for review.
https://gerrit.wikimedia.org/r/89237
Change subject: [WIP] exception: Move logging logic to static method of
MWExceptionHandler
......................................................................
[WIP] exception: Move logging logic to static method of MWExceptionHandler
This makes it possible to, for example, log PHP errors or errors
from Less in ResourceLoader to be logged as well (which naturally
don't have a logException method).
Not removing MWException::logException (introduced in bcb9f9e1c)
as it has been around since 2006 (released in 1.8.0).
Not deprecating MWException::getLogId (introduced in 70841c5867,
released in 1.20.0) as it is still useful to have MWException
have a fixed logId.
Change-Id: Iab98e3a7a9b78d8602e69e0571b35cf107a96b72
---
M includes/Exception.php
1 file changed, 67 insertions(+), 18 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core
refs/changes/37/89237/1
diff --git a/includes/Exception.php b/includes/Exception.php
index 39fe6f4..c513761 100644
--- a/includes/Exception.php
+++ b/includes/Exception.php
@@ -173,11 +173,12 @@
* This allows to link the exception to its corresponding log entry when
* $wgShowExceptionDetails is set to false.
*
+ * @since 1.20
* @return string
*/
function getLogId() {
if ( $this->logId === null ) {
- $this->logId = wfRandomString( 8 );
+ $this->logId = MWExceptionHandler::getLogId();
}
return $this->logId;
}
@@ -186,26 +187,13 @@
* Return the requested URL and point to file and line number from
which the
* exception occurred
*
+ * @since 1.8
+ * @deprecated since 1.22 Use MWExceptionHandler::getLogMessage instead.
* @return string
*/
function getLogMessage() {
- global $wgRequest;
-
- $id = $this->getLogId();
- $file = $this->getFile();
- $line = $this->getLine();
- $message = $this->getMessage();
-
- if ( isset( $wgRequest ) && !$wgRequest instanceof FauxRequest
) {
- $url = $wgRequest->getRequestURL();
- if ( !$url ) {
- $url = '[no URL]';
- }
- } else {
- $url = '[no req]';
- }
-
- return "[$id] $url Exception from line $line of $file:
$message";
+ wfDeprecated( __METHOD__, '1.22' );
+ return MWExceptionHandler::getLogMessage( $this,
$this->getLogId() );
}
/**
@@ -757,4 +745,65 @@
}
return $finalExceptionText . '#' . ( $i + 1 ) . ' {main}';
}
+
+
+ /**
+ * @since 1.22
+ * @param Exception $e
+ * @return string
+ */
+ protected static function getLogId( Exception $e ) {
+ return wfRandomString( 8 );
+ }
+
+ /**
+ * Return the requested URL and point to file and line number from
which the
+ * exception occurred.
+ *
+ * @since 1.22
+ * @param Exception $e
+ * @return string
+ */
+ protected static function getLogMessage( Exception $e ) {
+ global $wgRequest;
+
+ $id = self::getLogId();
+ $file = $e->getFile();
+ $line = $e->getLine();
+ $message = $e->getMessage();
+
+ if ( isset( $wgRequest ) && !$wgRequest instanceof FauxRequest
) {
+ $url = $wgRequest->getRequestURL();
+ if ( !$url ) {
+ $url = '[no URL]';
+ }
+ } else {
+ $url = '[no req]';
+ }
+
+ return "[$id] $url Exception from line $line of $file:
$message";
+ }
+
+ /**
+ * Log an exceptoin to the exception log (if enabled).
+ *
+ * This method must not assume the exception is an MWException,
+ * it is also used to handle PHP errors or errors from other libraries.
+ *
+ * @since 1.22
+ * @param Exception $e
+ */
+ public static function logException( Exception $e ) {
+ global $wgLogExceptionBacktrace;
+
+ $log = MWExceptionHandler::getLogMessage( $e );
+ if ( $log ) {
+ if ( $wgLogExceptionBacktrace ) {
+ wfDebugLog( 'exception', $log . "\n" .
MWExceptionHandler::formatRedactedTrace( $e ) . "\n" );
+ } else {
+ wfDebugLog( 'exception', $log );
+ }
+ }
+ }
+
}
--
To view, visit https://gerrit.wikimedia.org/r/89237
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Iab98e3a7a9b78d8602e69e0571b35cf107a96b72
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Krinkle <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits