improved error logging

This commit is contained in:
Steffen Schröder 2014-05-15 13:04:05 +02:00
parent 9a84a983d3
commit a6635f15c5
3 changed files with 25 additions and 25 deletions

View File

@ -54,7 +54,7 @@ class ErrorHandler {
$traceString = $exception->getTraceAsString();
$logMessage = $message . PHP_EOL . 'Class: ' . $exceptionClass . PHP_EOL . 'Trace:' . PHP_EOL . $traceString;
logMessage($logMessage);
$this->maniaControl->log($logMessage);
if ($this->reportErrors) {
$error = array();
@ -142,7 +142,7 @@ class ErrorHandler {
$traceString = $this->parseBackTrace(debug_backtrace());
$logMessage = $message . PHP_EOL . 'File&Line: ' . $fileLine . PHP_EOL . 'Trace: ' . $traceString;
logMessage($logMessage);
$this->maniaControl->log($logMessage);
if ($this->reportErrors && !$this->isUserErrorNumber($errorNumber)) {
$error = array();
@ -255,7 +255,7 @@ class ErrorHandler {
* @return bool
*/
private function isUserErrorNumber($errorNumber) {
return ($errorNumber === E_USER_ERROR || $errorNumber === E_USER_WARNING || $errorNumber === E_USER_NOTICE || $errorNumber === E_USER_DEPRECATED);
return ($errorNumber & E_USER_ERROR || $errorNumber & E_USER_WARNING || $errorNumber & E_USER_NOTICE || $errorNumber & E_USER_DEPRECATED);
}
/**
@ -265,7 +265,7 @@ class ErrorHandler {
* @return bool
*/
private function shouldStopExecution($errorNumber) {
return ($errorNumber === E_ERROR || $errorNumber === E_USER_ERROR || $errorNumber === E_FATAL);
return ($errorNumber & E_ERROR || $errorNumber & E_USER_ERROR || $errorNumber & E_FATAL);
}
/**

View File

@ -2,8 +2,8 @@
namespace ManiaControl\Files;
use ManiaControl\Utils\Formatter;
use ManiaControl\ManiaControl;
use ManiaControl\Utils\Formatter;
/**
* Files Utility Class
@ -77,11 +77,11 @@ abstract class FileUtil {
public static function loadConfig($fileName) {
$fileLocation = ManiaControlDir . 'configs' . DIRECTORY_SEPARATOR . $fileName;
if (!file_exists($fileLocation)) {
trigger_error("Config file doesn't exist! ({$fileName})");
logMessage("Config File doesn't exist! ({$fileName})");
return null;
}
if (!is_readable($fileLocation)) {
trigger_error("Config file isn't readable! Please check your file permissions. ({$fileName})");
logMessage("Config File isn't readable! Please check the File Permissions. ({$fileName})");
return null;
}
return simplexml_load_file($fileLocation);

View File

@ -156,13 +156,29 @@ class ManiaControl implements CommandListener, TimerListener {
$configFileName = ($configId ? $configId : 'server.xml');
$this->config = FileUtil::loadConfig($configFileName);
if (!$this->config) {
trigger_error("Error loading Configuration XML-File! ('{$configFileName}')", E_USER_ERROR);
$this->quit("Error loading Configuration XML-File! ('{$configFileName}')", true);
}
if (!$this->config->server->port || $this->config->server->port == 'port') {
trigger_error("Your Configuration File ('{$configFileName}') doesn't seem to be maintained. Please check it again!", E_USER_ERROR);
$this->quit("Your Configuration File ('{$configFileName}') doesn't seem to be maintained. Please check it again!", true);
}
}
/**
* Quit ManiaControl and log the given message
*
* @param string $message
* @param bool $errorPrefix
*/
public function quit($message = null, $errorPrefix = false) {
if ($message) {
if ($errorPrefix) {
$message = '[ERROR] ' . $message;
}
$this->log($message);
}
exit();
}
/**
* Check Connection
*/
@ -265,22 +281,6 @@ class ManiaControl implements CommandListener, TimerListener {
$this->quit("ManiaControl Shutdown requested by '{$player->login}'!");
}
/**
* Quit ManiaControl and log the given message
*
* @param string $message
* @param bool $errorPrefix
*/
public function quit($message = null, $errorPrefix = false) {
if ($message) {
if ($errorPrefix) {
$message = '[ERROR] ' . $message;
}
$this->log($message);
}
exit();
}
/**
* Handle PHP Process Shutdown
*/