send fatal errors

This commit is contained in:
kremsy 2014-02-13 20:41:55 +01:00 committed by Steffen Schröder
parent d7c26d04ae
commit 859c57e111
4 changed files with 26 additions and 6 deletions

View File

@ -5,6 +5,7 @@
define('LOG_WRITE_CURRENT_FILE', 'ManiaControl.log'); // Write current log to extra file in base dir
define('LOG_NAME_USE_DATE', true); // Use current date as suffix for log file name in logs folder
define('LOG_NAME_USE_PID', true); // Use current process id as suffix for log file name in logs folder
define('E_FATAL', E_ERROR | E_CORE_ERROR | E_COMPILE_ERROR | E_RECOVERABLE_ERROR | E_USER_ERROR);
// Define base dir
define('ManiaControlDir', __DIR__);

View File

@ -33,7 +33,7 @@ class ErrorHandler {
*/
public function exceptionHandler(\Exception $ex) {
$message = "[ManiaControl EXCEPTION]: {$ex->getMessage()}" . PHP_EOL;
$message .= "Class: ". get_class($ex) . PHP_EOL;
$message .= "Class: " . get_class($ex) . PHP_EOL;
$message .= "Trace: {$ex->getTraceAsString()}" . PHP_EOL;
logMessage($message);
@ -57,6 +57,8 @@ class ErrorHandler {
if (!json_decode($success)) {
logMessage("Exception-Report failed");
} else {
logMessage("Exception successfully reported!");
}
exit();
@ -101,11 +103,13 @@ class ErrorHandler {
$success = FileUtil::loadFile($url);
if (!json_decode($success)) {
logMessage("Error-Report failed");
logMessage("Error-Report failed!");
} else {
logMessage("Error successfully reported!");
}
}
if ($errorNumber == E_ERROR || $errorNumber == E_USER_ERROR) {
if ($errorNumber == E_ERROR || $errorNumber == E_USER_ERROR || $errorNumber == E_FATAL) {
logMessage('Stopping execution...');
exit();
}
@ -128,6 +132,15 @@ class ErrorHandler {
if ($errorLevel == E_ERROR) {
return '[PHP ERROR]';
}
if ($errorLevel == E_CORE_ERROR) {
return '[PHP CORE ERROR]';
}
if ($errorLevel == E_COMPILE_ERROR) {
return '[PHP COMPILE ERROR]';
}
if ($errorLevel == E_RECOVERABLE_ERROR) {
return '[PHP RECOVERABLE ERROR]';
}
if ($errorLevel == E_USER_NOTICE) {
return '[ManiaControl NOTICE]';
}

View File

@ -223,6 +223,12 @@ class ManiaControl implements CommandListener {
// Close the client connection
$this->client->delete($this->server->ip, $this->server->port);
//Check and Trigger Fatal Errors
$error = error_get_last();
if ($error && ($error['type'] & E_FATAL)) {
$this->errorHandler->errorHandler($error['type'], $error['message'], $error['file'], $error['line']);
}
$this->log('Quitting ManiaControl!');
exit();
}
@ -284,7 +290,7 @@ class ManiaControl implements CommandListener {
// Loading finished
$this->log('Loading completed!');
$this->log('Link: maniaplanet://#join=' . $this->server->login .'@' . $this->server->titleId);
$this->log('Link: maniaplanet://#join=' . $this->server->login . '@' . $this->server->titleId);
// Main loop
while(!$this->shutdownRequested) {