Add error-ids to SystemException
authorTim Düsterhus <timwolla@arcor.de>
Tue, 17 Apr 2012 18:21:06 +0000 (20:21 +0200)
committerTim Düsterhus <timwolla@arcor.de>
Tue, 17 Apr 2012 18:21:06 +0000 (20:21 +0200)
wcfsetup/install/files/lib/system/exception/LoggedException.class.php
wcfsetup/install/files/lib/system/exception/SystemException.class.php

index 2b7643414b509a2783319baa6b166d95b72e37b1..7bfa98e8f154586ac2361bf18f74590965e0821e 100644 (file)
@@ -1,13 +1,14 @@
 <?php
 namespace wcf\system\exception;
 use wcf\system\WCF;
+use wcf\util\StringUtil;
 
 /**
  * A logged exceptions prevents information disclosures and provides an easy
  * way to log errors.
  *
- * @author     Alexander Ebert
- * @copyright  2001-2011 WoltLab GmbH
+ * @author     Tim Düsterhus, Alexander Ebert
+ * @copyright  2001-2012 WoltLab GmbH
  * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
  * @package    com.woltlab.wcf
  * @subpackage system.exception
@@ -50,10 +51,23 @@ class LoggedException extends \Exception {
                }
                
                $e = ($this->getPrevious() ?: $this);
-               // build message
-               $message = date('r', TIME_NOW) . "\n" . $e->getMessage() . "\n\n" . $e->getTraceAsString() . "\n\n\n";
+               
+               $message = date('r', TIME_NOW)."\n".
+                       'Message: '.$e->getMessage()."\n".
+                       'File: '.$e->getFile().' ('.$e->getLine().")\n".
+                       'PHP version: '.phpversion()."\n".
+                       'WCF version: '.WCF_VERSION."\n".
+                       'Request URI: '.(isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '')."\n".
+                       'Referrer: '.(isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '')."\n".
+                       "Stacktrace: \n  ".implode("\n  ", explode("\n", $e->getTraceAsString()))."\n";
+               
+               // calculate Exception-ID
+               $id = StringUtil::getHash($message);
+               $message = "<<<<<<<<".$id."<<<<\n".$message."<<<<\n\n";
                
                // append
                @file_put_contents($logFile, $message, FILE_APPEND);
+               
+               return $id;
        }
 }
index faa15071fd906aed65e6feb9f208018c3ef295a3..f4ae20345f88537b0b9750e8298f9c09e14c078c 100644 (file)
@@ -70,7 +70,7 @@ class SystemException extends LoggedException implements IPrintableException {
         */
        public function show() {
                // log error
-               $this->logError();
+               $exceptionID = $this->logError();
                
                // send status code
                @header('HTTP/1.1 503 Service Unavailable');
@@ -153,9 +153,10 @@ class SystemException extends LoggedException implements IPrintableException {
                                        <?php if (WCF::debugModeIsEnabled()) { ?>
                                                <div>
                                                        <p><?php echo $this->getDescription(); ?></p>
-                                               
+                                                       
                                                        <h2>Information:</h2>
                                                        <p>
+                                                               <b>id:</b> <code><?php echo $exceptionID; ?></code><br>
                                                                <b>error message:</b> <?php echo StringUtil::encodeHTML($this->_getMessage()); ?><br>
                                                                <b>error code:</b> <?php echo intval($e->getCode()); ?><br>
                                                                <?php echo $this->information; ?>
@@ -166,12 +167,20 @@ class SystemException extends LoggedException implements IPrintableException {
                                                                <b>request:</b> <?php if (isset($_SERVER['REQUEST_URI']))  echo StringUtil::encodeHTML($_SERVER['REQUEST_URI']); ?><br>
                                                                <b>referer:</b> <?php if (isset($_SERVER['HTTP_REFERER'])) echo StringUtil::encodeHTML($_SERVER['HTTP_REFERER']); ?><br>
                                                        </p>
-
+                                                       
                                                        <h2>Stacktrace:</h2>
                                                        <pre><?php echo StringUtil::encodeHTML($this->__getTraceAsString()); ?></pre>
                                                </div>
+                                       <?php } else { ?>
+                                               <div>
+                                                       <h2>Information:</h2>
+                                                       <p>
+                                                               <b>id:</b> <code><?php echo $exceptionID; ?></code><br>
+                                                               Send this ID to the administrator of this website to report this issue.
+                                                       </p>
+                                               </div>
                                        <?php } ?>
-
+                                       
                                        <?php echo $this->functions; ?>
                                </div>
                        </body>