Merge "Improve "selfmove" message's wording"
[lhc/web/wiklou.git] / includes / exception / MWExceptionHandler.php
index a2867a1..a2ec391 100644 (file)
@@ -441,6 +441,24 @@ TXT;
                return "[$id] $url   $type from line $line of $file: $message";
        }
 
+       /**
+        * Get a normalised message for formatting with PSR-3 log event context.
+        *
+        * Must be used together with `getLogContext()` to be useful.
+        *
+        * @since 1.30
+        * @param Exception|Throwable $e
+        * @return string
+        */
+       public static function getLogNormalMessage( $e ) {
+               $type = get_class( $e );
+               $file = $e->getFile();
+               $line = $e->getLine();
+               $message = $e->getMessage();
+
+               return "[{exception_id}] {exception_url}   $type from line $line of $file: $message";
+       }
+
        /**
         * @param Exception|Throwable $e
         * @return string
@@ -468,6 +486,7 @@ TXT;
                return [
                        'exception' => $e,
                        'exception_id' => WebRequest::getRequestId(),
+                       'exception_url' => self::getURL() ?: '[no req]',
                        'caught_by' => $catcher
                ];
        }
@@ -595,7 +614,7 @@ TXT;
                if ( !( $e instanceof MWException ) || $e->isLoggable() ) {
                        $logger = LoggerFactory::getInstance( 'exception' );
                        $logger->error(
-                               self::getLogMessage( $e ),
+                               self::getLogNormalMessage( $e ),
                                self::getLogContext( $e, $catcher )
                        );
 
@@ -616,7 +635,7 @@ TXT;
         * @param ErrorException $e
         * @param string $channel
         * @param string $level
-       */
+        */
        protected static function logError(
                ErrorException $e, $channel, $level = LogLevel::ERROR
        ) {
@@ -629,7 +648,7 @@ TXT;
                        $logger = LoggerFactory::getInstance( $channel );
                        $logger->log(
                                $level,
-                               self::getLogMessage( $e ),
+                               self::getLogNormalMessage( $e ),
                                self::getLogContext( $e, $catcher )
                        );
                }