be a good idea, but will log out all current sessions.
* $wgEventRelayerConfig was added, for managing PubSub event relay configuration,
specifically for reliable CDN url purges.
+* Requests have unique IDs, equal to the UNIQUE_ID environment variable (when
+ MediaWiki is behind Apache+mod_unique_id or something similar) or a randomly-
+ generated 24-character string. This request ID is used to annotate log records
+ and error messages. It is available client-side via mw.config.get( 'wgRequestId' ).
+ The request ID supplants exception IDs. Accordingly, MWExceptionHandler::getLogId()
+ is deprecated.
=== External library changes in 1.27 ===
'wgMonthNamesShort' => $lang->getMonthAbbreviationsArray(),
'wgRelevantPageName' => $relevantTitle->getPrefixedDBkey(),
'wgRelevantArticleId' => $relevantTitle->getArticleID(),
+ 'wgRequestId' => WebRequest::getRequestId(),
];
if ( $user->isLoggedIn() ) {
return microtime( true ) - $this->requestTime;
}
+ /**
+ * Get the unique request ID.
+ * This is either the value of the UNIQUE_ID envvar (if present) or a
+ * randomly-generated 24-character string.
+ *
+ * @return string
+ * @since 1.27
+ */
+ public static function getRequestId() {
+ static $reqId;
+
+ if ( !$reqId ) {
+ $reqId = isset( $_SERVER['UNIQUE_ID'] )
+ ? $_SERVER['UNIQUE_ID'] : wfRandomString( 24 );
+ }
+
+ return $reqId;
+ }
+
/**
* Get the current URL protocol (http or https)
* @return string
$errMessage = [
'code' => 'internal_api_error_' . get_class( $e ),
- 'info' => '[' . MWExceptionHandler::getLogId( $e ) . '] ' . $info,
+ 'info' => '[' . WebRequest::getRequestId() . '] ' . $info,
];
}
return $errMessage;
namespace MediaWiki\Logger\Monolog;
/**
- * Injects `wfHostname()`, `wfWikiID()` and `$wgVersion` in all records.
+ * Annotate log records with request-global metadata, such as the hostname,
+ * wiki / request ID, and MediaWiki version.
*
* @since 1.25
* @author Bryan Davis <bd808@wikimedia.org>
'host' => wfHostname(),
'wiki' => wfWikiID(),
'mwversion' => $wgVersion,
+ 'reqId' => WebRequest::getRequestId(),
]
);
return $record;
nl2br( htmlspecialchars( MWExceptionHandler::getRedactedTraceAsString( $this ) ) ) .
"</p>\n";
} else {
- $logId = MWExceptionHandler::getLogId( $this );
+ $logId = WebRequest::getRequestId();
$type = get_class( $this );
return "<div class=\"errorbox\">" .
'[' . $logId . '] ' .
* $wgShowExceptionDetails is set to false), to the entry in the debug log.
*
* @since 1.22
+ * @deprecated since 1.27: Exception IDs are synonymous with request IDs.
* @param Exception|Throwable $e
* @return string
*/
public static function getLogId( $e ) {
- if ( !isset( $e->_mwLogId ) ) {
- $e->_mwLogId = wfRandomString( 8 );
- }
- return $e->_mwLogId;
+ wfDeprecated( __METHOD__, '1.27' );
+ return WebRequest::getRequestId();
}
/**
* @return string
*/
public static function getLogMessage( $e ) {
- $id = self::getLogId( $e );
+ $id = WebRequest::getRequestId();
$type = get_class( $e );
$file = $e->getFile();
$line = $e->getLine();
}
public static function getPublicLogMessage( Exception $e ) {
- $logId = self::getLogId( $e );
+ $reqId = WebRequest::getRequestId();
$type = get_class( $e );
- return '[' . $logId . '] '
+ return '[' . $reqId . '] '
. gmdate( 'Y-m-d H:i:s' ) . ': '
. 'Fatal exception of type ' . $type;
}
public static function getLogContext( $e ) {
return [
'exception' => $e,
- 'exception_id' => static::getLogId( $e ),
+ 'exception_id' => WebRequest::getRequestId(),
];
}
public static function getStructuredExceptionData( $e ) {
global $wgLogExceptionBacktrace;
$data = [
- 'id' => self::getLogId( $e ),
+ 'id' => WebRequest::getRequestId(),
'type' => get_class( $e ),
'file' => $e->getFile(),
'line' => $e->getLine(),