Log exceptions
authorTim Starling <tstarling@users.mediawiki.org>
Wed, 2 Aug 2006 17:40:09 +0000 (17:40 +0000)
committerTim Starling <tstarling@users.mediawiki.org>
Wed, 2 Aug 2006 17:40:09 +0000 (17:40 +0000)
includes/Database.php
includes/Exception.php

index 1812cd1..1acb83c 100644 (file)
@@ -86,6 +86,11 @@ class DBConnectionError extends DBError {
                return $this->getMessage() . "\n";
        }
 
+       function getLogMessage() {
+               # Don't send to the exception log
+               return false;
+       }
+
        function getPageTitle() {
                global $wgSitename;
                return "$wgSitename has a problem";
@@ -205,6 +210,11 @@ class DBQueryError extends DBError {
                }
        }
        
+       function getLogMessage() {
+               # Don't send to the exception log
+               return false;
+       }
+
        function getPageTitle() {
                return $this->msg( 'databaseerror', 'Database error' );
        }
index 027c5d3..696454d 100644 (file)
@@ -41,6 +41,13 @@ class MWException extends Exception
                }
        }
        
+       function getLogMessage() {
+               $file = $this->getFile();
+               $line = $this->getLine();
+               $message = $this->getMessage();
+               return "{$_SERVER['REQUEST_URI']} Exception from line $line of $file: $message";
+       }
+       
        function reportHTML() {
                global $wgOut;
                if ( $this->useOutputPage() ) {
@@ -68,6 +75,10 @@ class MWException extends Exception
                if ( $wgCommandLineMode ) {
                        $this->reportText();
                } else {
+                       $log = $this->getLogMessage();
+                       if ( $log ) {
+                               wfDebugLog( 'exception', $log );
+                       }
                        $this->reportHTML();
                }
        }
@@ -95,6 +106,7 @@ class MWException extends Exception
        function htmlFooter() {
                echo "</body></html>";
        }
+
 }
 
 /**