From ff707bba775134de0b39cfb5f643387e53d56caa Mon Sep 17 00:00:00 2001 From: Marius Hoch Date: Tue, 6 Jan 2015 12:36:28 +0100 Subject: [PATCH] Don't log HttpErrors in the exception log, use MWLogger Bug: T85795 Change-Id: Ic36f657a6447dd99c78681536e5dfb066d97b409 --- includes/exception/HttpError.php | 40 +++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/includes/exception/HttpError.php b/includes/exception/HttpError.php index 6ab6e03929..051556623b 100644 --- a/includes/exception/HttpError.php +++ b/includes/exception/HttpError.php @@ -42,6 +42,19 @@ class HttpError extends MWException { $this->content = $content; } + /** + * 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. * @@ -52,11 +65,13 @@ class HttpError extends MWException { } /** - * 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,29 @@ class HttpError extends MWException { print $this->getHTML(); } + private function doLog() { + $logger = MWLoggerFactory::getInstance( 'HttpError' ); + $content = $this->content; + + if ( $content instanceof Message ) { + $content = $content->text(); + } + + $context = array( + 'file' => $this->getFile(), + 'line' => $this->getLine(), + 'http_code' => $this->httpCode, + ); + + $logMsg = "$content ({http_code}) from {file}:{line}"; + + if ( $this->getStatusCode() < 500 ) { + $logger->info( $logMsg, $context ); + } else { + $logger->error( $logMsg, $context ); + } + } + /** * Returns HTML for reporting the HTTP error. * This will be a minimal but complete HTML document. -- 2.20.1