Hoo man has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/183020

Change subject: Don't log HttpErrors in the exception log
......................................................................

Don't log HttpErrors in the exception log

Rather use the new HttpError debug log group.

For http errors from 500 on I've also introduced a
special HttpError-5XX  log group, in case someone
wants to log only these.

Bug: T85795
Change-Id: Ic36f657a6447dd99c78681536e5dfb066d97b409
---
M includes/exception/HttpError.php
1 file changed, 32 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/20/183020/1

diff --git a/includes/exception/HttpError.php b/includes/exception/HttpError.php
index 6ab6e03..b6f79ee 100644
--- a/includes/exception/HttpError.php
+++ b/includes/exception/HttpError.php
@@ -43,6 +43,19 @@
        }
 
        /**
+        * We don't want the default exception logging as we got our own 
logging set
+        * up in self::report.
+        *
+        * @see MWException::isLoggable
+        *
+        * @since 1.24
+        * @return bool
+        */
+       public function isLoggable() {
+               return false;
+       }
+
+       /**
         * Returns the HTTP status code supplied to the constructor.
         *
         * @return int
@@ -52,11 +65,13 @@
        }
 
        /**
-        * Report the HTTP error.
+        * Report and log the HTTP error.
         * Sends the appropriate HTTP status code and outputs an
         * HTML page with an error message.
         */
        public function report() {
+               $this->doLog();
+
                $httpMessage = HttpStatus::getMessage( $this->httpCode );
 
                header( "Status: {$this->httpCode} {$httpMessage}", true, 
$this->httpCode );
@@ -65,6 +80,22 @@
                print $this->getHTML();
        }
 
+       private function doLog() {
+               $content = $this->content;
+
+               if ( $content instanceof Message ) {
+                       $content = $content->text();
+               }
+
+               $logMsg = $content . ' (' . $this->httpCode . ') from ' . 
$this->getFile() . ':' . $this->getLine();
+
+               wfDebugLog( 'HttpError', $logMsg );
+
+               if ( $this->getStatusCode() >= 500 ) {
+                       wfDebugLog( 'HttpError-5XX', $logMsg );
+               }
+       }
+
        /**
         * Returns HTML for reporting the HTTP error.
         * This will be a minimal but complete HTML document.

-- 
To view, visit https://gerrit.wikimedia.org/r/183020
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ic36f657a6447dd99c78681536e5dfb066d97b409
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Hoo man <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to