From: Tim Düsterhus Date: Tue, 1 Dec 2015 22:28:55 +0000 (+0100) Subject: Adapt ExceptionLogViewPage X-Git-Tag: 3.0.0_Beta_1~2094^2~2 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=2b6fbe9404e67893ce55c9af133bcc61c77e0085;p=GitHub%2FWoltLab%2FWCF.git Adapt ExceptionLogViewPage --- diff --git a/wcfsetup/install/files/acp/templates/exceptionLogView.tpl b/wcfsetup/install/files/acp/templates/exceptionLogView.tpl index 1626fdebe1..ae2d43ae80 100644 --- a/wcfsetup/install/files/acp/templates/exceptionLogView.tpl +++ b/wcfsetup/install/files/acp/templates/exceptionLogView.tpl @@ -80,10 +80,6 @@
{$exception[date]|strtotime|plainTime}
-
-
{lang}wcf.acp.exceptionLog.exception.file{/lang}
-
{$exception[file]} ({$exception[line]})
-
{lang}wcf.acp.exceptionLog.exception.requestURI{/lang}
{$exception[requestURI]}
@@ -96,20 +92,34 @@
{lang}wcf.acp.exceptionLog.exception.userAgent{/lang}
{$exception[userAgent]}
- {if $exception[information]} -
-
{lang}wcf.acp.exceptionLog.exception.information{/lang}
-
{@$exception[information]}
-
- {/if} +
+
{lang}wcf.acp.exceptionLog.exception.memory{/lang}
+
{$exception[peakMemory]|filesizeBinary} / {$exception[maxMemory]|filesizeBinary}
+
+ {foreach from=$exception[chain] item=chain} +
+
{lang}wcf.acp.exceptionLog.exception.message{/lang}
+
{$chain[message]}
+
+
+
{lang}wcf.acp.exceptionLog.exception.class{/lang}
+
{$chain[class]}
+
+
+
{lang}wcf.acp.exceptionLog.exception.file{/lang}
+
{$chain[file]} ({$chain[line]})
+
{lang}wcf.acp.exceptionLog.exception.stacktrace{/lang}
-
-
    -
  • {@"
  • "|implode:$exception[stacktrace]}
  • +
    +
      + {foreach from=$chain[stack] item=stack} +
    1. {$stack[file]} ({$stack[line]}): {$stack[class]}{$stack[type]}{$stack[function]}(…)
    2. + {/foreach}
+ {/foreach}
diff --git a/wcfsetup/install/files/lib/acp/page/ExceptionLogViewPage.class.php b/wcfsetup/install/files/lib/acp/page/ExceptionLogViewPage.class.php index 03f8e27912..e1edef30cf 100644 --- a/wcfsetup/install/files/lib/acp/page/ExceptionLogViewPage.class.php +++ b/wcfsetup/install/files/lib/acp/page/ExceptionLogViewPage.class.php @@ -135,17 +135,23 @@ class ExceptionLogViewPage extends MultipleLinkPage { $i = 0; // TODO: This needs to be adapted for WCF 2.2 - $exceptionRegex = new Regex('(?P[MTWFS][a-z]{2}, \d{1,2} [JFMASOND][a-z]{2} \d{4} \d{2}:\d{2}:\d{2} [+-]\d{4}) -Message: (?P.*?) -File: (?P.*?) \((?P\d+)\) -PHP version: (?P.*?) -WCF version: (?P.*?) -Request URI: (?P.*?) -Referrer: (?P.*?) -User-Agent: (?P.*?) -Information: (?P.*?) -Stacktrace: -(?P.*)', Regex::DOT_ALL); + $exceptionRegex = new Regex('(?P[MTWFS][a-z]{2}, \d{1,2} [JFMASOND][a-z]{2} \d{4} \d{2}:\d{2}:\d{2} [+-]\d{4})\s* +Message: (?P.*?)\s* +PHP version: (?P.*?)\s* +WCF version: (?P.*?)\s* +Request URI: (?P.*?)\s* +Referrer: (?P.*?)\s* +User Agent: (?P.*?)\s* +Peak Memory Usage: (?\d+)/(?\d+)\s* +(?====== +.*)', Regex::DOT_ALL); + $chainRegex = new Regex('====== +Error Class: (?P.*?)\s* +Error Message: (?P.*?)\s* +Error Code: (?P\d+)\s* +File: (?P.*?) \((?P\d+)\)\s* +Extra Information: (?P(?:-|[a-zA-Z0-9+/]+={0,2}))\s* +Stack Trace: (?P[a-zA-Z0-9+/]+={0,2})', Regex::DOT_ALL); $stackTraceFormatter = new Regex('^\s+(#\d+)', Regex::MULTILINE); foreach ($this->exceptions as $key => $val) { $i++; @@ -158,10 +164,20 @@ Stacktrace: unset($this->exceptions[$key]); continue; } + $matches = $exceptionRegex->getMatches(); + $chainRegex->match($matches['chain'], true, Regex::ORDER_MATCH_BY_SET); - $this->exceptions[$key] = $exceptionRegex->getMatches(); - $this->exceptions[$key]['stacktrace'] = explode("\n", $stackTraceFormatter->replace(StringUtil::encodeHTML($this->exceptions[$key]['stacktrace']), '\\1')); - $this->exceptions[$key]['information'] = JSON::decode($this->exceptions[$key]['information']); + $chainMatches = array_map(function ($item) { + if ($item['information'] === '-') $item['information'] = null; + else $item['information'] = @unserialize(base64_decode($item['information'])); + + $item['stack'] = @unserialize(base64_decode($item['stack'])); + + return $item; + }, $chainRegex->getMatches()); + + $matches['chain'] = $chainMatches; + $this->exceptions[$key] = $matches; } } diff --git a/wcfsetup/install/files/lib/core.functions.php b/wcfsetup/install/files/lib/core.functions.php index f9b45b1083..62092c8aec 100644 --- a/wcfsetup/install/files/lib/core.functions.php +++ b/wcfsetup/install/files/lib/core.functions.php @@ -8,7 +8,7 @@ */ namespace { use wcf\system\WCF; - + // set exception handler set_exception_handler([ WCF::class, 'handleException' ]); // set php error handler @@ -17,12 +17,12 @@ namespace { register_shutdown_function([ WCF::class, 'destruct' ]); // set autoload function spl_autoload_register([ WCF::class, 'autoload' ]); - + // define escape string shortcut function escapeString($string) { return WCF::getDB()->escapeString($string); } - + // define DOCUMENT_ROOT on IIS if not set if (PHP_EOL == "\r\n") { if (!isset($_SERVER['DOCUMENT_ROOT']) && isset($_SERVER['SCRIPT_FILENAME'])) { @@ -31,7 +31,7 @@ namespace { if (!isset($_SERVER['DOCUMENT_ROOT']) && isset($_SERVER['PATH_TRANSLATED'])) { $_SERVER['DOCUMENT_ROOT'] = str_replace( '\\', '/', substr(str_replace('\\\\', '\\', $_SERVER['PATH_TRANSLATED']), 0, 0 - strlen($_SERVER['PHP_SELF']))); } - + if (!isset($_SERVER['REQUEST_URI'])) { $_SERVER['REQUEST_URI'] = substr($_SERVER['PHP_SELF'], 1); if (isset($_SERVER['QUERY_STRING'])) { @@ -47,11 +47,11 @@ namespace wcf\functions\exception { use wcf\system\WCF; use wcf\util\FileUtil; use wcf\util\StringUtil; - + function logThrowable($e) { $logFile = WCF_DIR . 'log/' . gmdate('Y-m-d', TIME_NOW) . '.txt'; touch($logFile); - + // don't forget to update ExceptionLogViewPage, when changing the log file format $message = gmdate('r', TIME_NOW)."\n". 'Message: '.str_replace("\n", ' ', $e->getMessage())."\n". @@ -81,20 +81,20 @@ namespace wcf\functions\exception { return $item; } }, $item['args']); - + return $item; }, sanitizeStacktrace($e, true))))."\n"; } while ($e = $e->getPrevious()); - + // calculate Exception-ID $exceptionID = sha1($message); - $entry = "<<<<<<<<".$exceptionID."<<<<\n".$message."<<<<\n"; - + $entry = "<<<<<<<<".$exceptionID."<<<<\n".$message."<<<<\n\n"; + file_put_contents($logFile, $entry, FILE_APPEND); return $exceptionID; } - + function printThrowable($e) { $exceptionID = logThrowable($e); // TODO ?> @@ -201,10 +201,10 @@ namespace wcf\functions\exception { $message = str_replace('{$exceptionID}', $exceptionID, WCF::getLanguage()->get('wcf.global.error.exception', true)); } catch (\Exception $e) { - + } catch (\Throwable $e) { - + } echo $message; ?> @@ -241,7 +241,7 @@ namespace wcf\functions\exception { ob_start(); $e->show(); ob_end_clean(); - + $reflection = new \ReflectionClass($e); $property = $reflection->getProperty('information'); $property->setAccessible(true); @@ -257,14 +257,7 @@ namespace wcf\functions\exception { ?>
Stack Trace
getTrace(); - + return array_map(function ($item) use ($ignorePaths) { + if (!isset($item['file'])) $item['file'] = '[internal function]'; + if (!isset($item['line'])) $item['line'] = '?'; + if (!isset($item['class'])) $item['class'] = ''; + if (!isset($item['type'])) $item['type'] = ''; + // strip database credentials - if (isset($item['class'])) { - if (preg_match('~\\\\?wcf\\\\system\\\\database\\\\[a-zA-Z]*Database~', $item['class']) || $item['class'] === 'PDO') { - if ($item['function'] === '__construct') { - $item['args'] = array_map(function () { - return '[redacted]'; - }, $item['args']); - } + if (preg_match('~\\\\?wcf\\\\system\\\\database\\\\[a-zA-Z]*Database~', $item['class']) || $item['class'] === 'PDO') { + if ($item['function'] === '__construct') { + $item['args'] = array_map(function () { + return '[redacted]'; + }, $item['args']); } } - + if (!$ignorePaths) { $item['args'] = array_map(function ($item) { if (!is_string($item)) return $item; - + if (preg_match('~^'.preg_quote($_SERVER['DOCUMENT_ROOT'], '~').'~', $item)) { $item = sanitizePath($item); } - + return preg_replace('~^'.preg_quote(WCF_DIR, '~').'~', '*/', $item); }, $item['args']); - - if (isset($item['file'])) $item['file'] = sanitizePath($item['file']); + + $item['file'] = sanitizePath($item['file']); } - + return $item; }, $trace); } @@ -345,7 +341,7 @@ namespace wcf\functions\exception { if (WCF::debugModeIsEnabled() && defined('EXCEPTION_PRIVACY') && EXCEPTION_PRIVACY === 'public') { return $path; } - + return '*/'.FileUtil::removeTrailingSlash(FileUtil::getRelativePath(WCF_DIR, $path)); } } diff --git a/wcfsetup/install/lang/de.xml b/wcfsetup/install/lang/de.xml index 5dfa0906a6..003e3d85ad 100644 --- a/wcfsetup/install/lang/de.xml +++ b/wcfsetup/install/lang/de.xml @@ -249,10 +249,11 @@ + + - diff --git a/wcfsetup/install/lang/en.xml b/wcfsetup/install/lang/en.xml index 8069a6de82..00801e80a3 100644 --- a/wcfsetup/install/lang/en.xml +++ b/wcfsetup/install/lang/en.xml @@ -248,10 +248,11 @@ Examples for medium ID detection: + + -