From: Tim Düsterhus Date: Tue, 29 Sep 2015 20:04:30 +0000 (+0200) Subject: Add new exception log format X-Git-Tag: 3.0.0_Beta_1~2094^2~8 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=b814936984a3f525c6ce51b7c496fbb9c350760c;p=GitHub%2FWoltLab%2FWCF.git Add new exception log format --- diff --git a/wcfsetup/install/files/lib/acp/page/ExceptionLogViewPage.class.php b/wcfsetup/install/files/lib/acp/page/ExceptionLogViewPage.class.php index 8c15b577f6..03f8e27912 100644 --- a/wcfsetup/install/files/lib/acp/page/ExceptionLogViewPage.class.php +++ b/wcfsetup/install/files/lib/acp/page/ExceptionLogViewPage.class.php @@ -134,6 +134,7 @@ class ExceptionLogViewPage extends MultipleLinkPage { $this->calculateNumberOfPages(); $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+)\) diff --git a/wcfsetup/install/files/lib/core.functions.php b/wcfsetup/install/files/lib/core.functions.php index 5d586439fb..4649cabdd9 100644 --- a/wcfsetup/install/files/lib/core.functions.php +++ b/wcfsetup/install/files/lib/core.functions.php @@ -48,8 +48,55 @@ namespace wcf\functions\exception { 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". + 'PHP version: '.phpversion()."\n". + 'WCF version: '.WCF_VERSION."\n". + 'Request URI: '.(isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '')."\n". + 'Referrer: '.(isset($_SERVER['HTTP_REFERER']) ? str_replace("\n", ' ', $_SERVER['HTTP_REFERER']) : '')."\n". + 'User Agent: '.(isset($_SERVER['HTTP_USER_AGENT']) ? str_replace("\n", ' ', $_SERVER['HTTP_USER_AGENT']) : '')."\n". + 'Peak Memory Usage: '.memory_get_peak_usage().'/'.FileUtil::getMemoryLimit()."\n"; + do { + $message .= "======\n". + 'Error Class: '.get_class($e)."\n". + 'Error Message: '.str_replace("\n", ' ', $e->getMessage())."\n". + 'Error Code: '.intval($e->getCode())."\n". + 'File: '.str_replace("\n", ' ', $e->getFile()).' ('.$e->getLine().')'."\n". + 'Extra Information: '.($e instanceof IExtraInformationException ? base64_encode(serialize($e->getExtraInformation())) : '-')."\n". + 'Stack Trace: '.base64_encode(serialize(array_map(function ($item) { + $item['args'] = array_map(function ($item) { + switch (gettype($item)) { + case 'object': + return get_class($item); + case 'array': + return array_map(function () { + return '[redacted]'; + }, $item); + default: + 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"; + + file_put_contents($logFile, $entry, FILE_APPEND); + return $exceptionID; + } + function printThrowable($e) { - $exceptionID = '123456'; // TODO + $exceptionID = logThrowable($e); // TODO ?>