error reports: backtrace split from message

This commit is contained in:
Steffen Schröder 2014-03-19 14:00:24 +01:00
parent 57375a6e8b
commit 4d5280ce8f
5 changed files with 52 additions and 14 deletions

View File

@ -38,15 +38,16 @@ class ErrorHandler {
* @param \Exception $ex * @param \Exception $ex
*/ */
public function exceptionHandler(\Exception $ex) { public function exceptionHandler(\Exception $ex) {
$message = "[ManiaControl EXCEPTION]: {$ex->getMessage()}" . PHP_EOL; $message = "[ManiaControl EXCEPTION]: {$ex->getMessage()}";
$message .= "Class: " . get_class($ex) . PHP_EOL; $traceMessage = 'Class: ' . get_class($ex) . PHP_EOL;
$message .= "Trace: {$ex->getTraceAsString()}" . PHP_EOL; $traceMessage .= 'Trace:' . PHP_EOL . $ex->getTraceAsString();
logMessage($message); logMessage($message . PHP_EOL . $traceMessage);
if ($this->reportErrors) { if ($this->reportErrors) {
$error = array(); $error = array();
$error["Type"] = "Exception"; $error["Type"] = "Exception";
$error["Message"] = $message; $error["Message"] = $message;
$error["Backtrace"] = $traceMessage;
$error['OperatingSystem'] = php_uname(); $error['OperatingSystem'] = php_uname();
$error['PHPVersion'] = phpversion(); $error['PHPVersion'] = phpversion();
@ -102,13 +103,15 @@ class ErrorHandler {
// Log error // Log error
$errorTag = $this->getErrorTag($errorNumber); $errorTag = $this->getErrorTag($errorNumber);
$message = "{$errorTag}: {$errorString} in File '{$errorFile}' on Line {$errorLine}!"; $message = $errorTag . ': ' . $errorString;
logMessage($message); $traceMessage = $this->parseBackTrace(debug_backtrace());
logMessage($message . PHP_EOL . $traceMessage);
if ($this->reportErrors && $errorNumber != E_USER_ERROR && $errorNumber != E_USER_WARNING && $errorNumber != E_USER_NOTICE) { if ($this->reportErrors && $errorNumber != E_USER_ERROR && $errorNumber != E_USER_WARNING && $errorNumber != E_USER_NOTICE) {
$error = array(); $error = array();
$error["Type"] = "Error"; $error["Type"] = "Error";
$error["Message"] = $message; $error["Message"] = $message;
$error["Backtrace"] = $traceMessage;
$error['OperatingSystem'] = php_uname(); $error['OperatingSystem'] = php_uname();
$error['PHPVersion'] = phpversion(); $error['PHPVersion'] = phpversion();
@ -200,4 +203,36 @@ class ErrorHandler {
} }
return "[PHP {$errorLevel}]"; return "[PHP {$errorLevel}]";
} }
/**
* Parse the Debug Backtrace into a String for the Error Report
*
* return string
*/
private function parseBackTrace(array $backtrace) {
$traceString = 'Trace:';
$stepCount = 0;
foreach ($backtrace as $traceStep) {
$traceString .= PHP_EOL . '#' . $stepCount . ': ';
if (isset($traceStep['class'])) {
$traceString .= $traceStep['class'];
}
if (isset($traceStep['type'])) {
$traceString .= $traceStep['type'];
}
if (isset($traceStep['function'])) {
$traceString .= $traceStep['function'];
}
if (isset($traceStep['file'])) {
$traceString .= ' in File ';
$traceString .= $traceStep['file'];
}
if (isset($traceStep['line'])) {
$traceString .= ' on Line ';
$traceString .= $traceStep['line'];
}
$stepCount++;
}
return $traceString;
}
} }

View File

@ -127,7 +127,6 @@ class ManiaControl implements CommandListener, TimerListener {
$this->commandManager->registerCommandListener('shutdown', $this, 'command_Shutdown', true); $this->commandManager->registerCommandListener('shutdown', $this, 'command_Shutdown', true);
} }
/** /**
* Print a message to console and log * Print a message to console and log
* *

View File

@ -214,8 +214,8 @@ class MapQueue implements CallbackListener, CommandListener {
public function getQueuedMapsRanking() { public function getQueuedMapsRanking() {
$i = 1; $i = 1;
$queuedMaps = array(); $queuedMaps = array();
foreach($this->queuedMaps as $map) { foreach($this->queuedMaps as $queuedMap) {
$map = $map[1]; $map = $queuedMap[1];
$queuedMaps[$map->uid] = $i; $queuedMaps[$map->uid] = $i;
$i++; $i++;
} }

View File

@ -844,7 +844,7 @@ class Dedimania implements CallbackListener, TimerListener, Plugin {
} }
/** /**
* Encodes the given xml rpc method and params * Encode the given xml rpc method and params
* *
* @param string $method * @param string $method
* @param array $params * @param array $params
@ -856,7 +856,7 @@ class Dedimania implements CallbackListener, TimerListener, Plugin {
} }
/** /**
* Handles xml rpc fault * Handle xml rpc fault
* *
* @param $fault * @param $fault
* @param $method * @param $method
@ -865,10 +865,14 @@ class Dedimania implements CallbackListener, TimerListener, Plugin {
trigger_error('XmlRpc Fault on ' . $method . ': ' . $fault['faultString'] . ' (' . $fault['faultCode'] . ')'); trigger_error('XmlRpc Fault on ' . $method . ': ' . $fault['faultString'] . ' (' . $fault['faultCode'] . ')');
} }
/**
* Build Manialink
*
* @return \FML\ManiaLink
*/
private function buildManialink() { private function buildManialink() {
if (!$this->dedimaniaData->records) { if (!$this->dedimaniaData->records) {
return ''; return null;
} }
$records = $this->dedimaniaData->records; $records = $this->dedimaniaData->records;

View File

@ -448,7 +448,7 @@ class WidgetPlugin implements CallbackListener, TimerListener, Plugin {
*/ */
$requester = null; $requester = null;
// if the nextmap is not a queued map, get it from map info // if the nextmap is not a queued map, get it from map info
if ($queuedMap == null) { if (!$queuedMap) {
$map = $this->maniaControl->client->getNextMapInfo(); $map = $this->maniaControl->client->getNextMapInfo();
$name = Formatter::stripDirtyCodes($map->name); $name = Formatter::stripDirtyCodes($map->name);
$author = $map->author; $author = $map->author;