+ public static function getPublicLogMessage( Exception $e ) {
+ $logId = self::getLogId( $e );
+ $type = get_class( $e );
+ return '[' . $logId . '] '
+ . gmdate( 'Y-m-d H:i:s' ) . ': '
+ . 'Fatal exception of type ' . $type;
+ }
+
+ /**
+ * Get a PSR-3 log event context from an Exception.
+ *
+ * Creates a structured array containing information about the provided
+ * exception that can be used to augment a log message sent to a PSR-3
+ * logger.
+ *
+ * @param Exception|Throwable $e
+ * @return array
+ */
+ public static function getLogContext( $e ) {
+ return array(
+ 'exception' => $e,
+ 'exception_id' => static::getLogId( $e ),
+ );
+ }
+
+ /**
+ * Get a structured representation of an Exception.
+ *
+ * Returns an array of structured data (class, message, code, file,
+ * backtrace) derived from the given exception. The backtrace information
+ * will be redacted as per getRedactedTraceAsArray().
+ *
+ * @param Exception|Throwable $e
+ * @return array
+ * @since 1.26
+ */
+ public static function getStructuredExceptionData( $e ) {
+ global $wgLogExceptionBacktrace;
+ $data = array(
+ 'id' => self::getLogId( $e ),
+ 'type' => get_class( $e ),
+ 'file' => $e->getFile(),
+ 'line' => $e->getLine(),
+ 'message' => $e->getMessage(),
+ 'code' => $e->getCode(),
+ 'url' => self::getURL() ?: null,
+ );
+
+ if ( $e instanceof ErrorException &&
+ ( error_reporting() & $e->getSeverity() ) === 0
+ ) {
+ // Flag surpressed errors
+ $data['suppressed'] = true;
+ }
+
+ if ( $wgLogExceptionBacktrace ) {
+ $data['backtrace'] = self::getRedactedTrace( $e );
+ }
+
+ $previous = $e->getPrevious();
+ if ( $previous !== null ) {
+ $data['previous'] = self::getStructuredExceptionData( $previous );
+ }
+
+ return $data;
+ }
+