From f5c99ea06408afb809b5b57465533f1ea6cfb0c8 Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Tue, 15 Aug 2017 23:24:42 +0200 Subject: [PATCH] #375 fixed loop in error db writer, log all errors except certain exceptions --- db/connection/ConnectionMYS.php | 5 ++--- log/error_handler/error_handler_dbwriter.php | 9 ++------- log/exceptions/DEPRECATED.php | 2 +- log/exceptions/ERROR.php | 2 +- log/exceptions/INFO.php | 5 ++++- log/exceptions/SYSTEM_ERROR_EXCEPTION.php | 2 -- log/exceptions/SYSTEM_EXCEPTION.php | 10 +++------- log/exceptions/TODO.php | 3 +-- log/exceptions/WARNING.php | 2 +- 9 files changed, 15 insertions(+), 25 deletions(-) diff --git a/db/connection/ConnectionMYS.php b/db/connection/ConnectionMYS.php index 1e910c0..4579c1f 100644 --- a/db/connection/ConnectionMYS.php +++ b/db/connection/ConnectionMYS.php @@ -28,11 +28,10 @@ class ConnectionMYS extends ConnectionAbstr { public function __construct(DBInfo $dbinfo, $new_link = false, $client_flag = 0){ $this->connection = @mysqli_connect($dbinfo->m_host, $dbinfo->m_user, $dbinfo->m_password, $new_link, $client_flag); if(!$this->connection){ - die('Could not connect to Database. Check ur Database Settings');} + die('Could not connect to Database. Check ur Database Settings.');} if(!mysqli_select_db($this->connection, $dbinfo->m_database)){ - mysqli_close($this->connection); - die('Could not select Database. Check ur Database Settings: '.mysqli_error($this->connection));} + die('Could not select Database. Check ur Database Settings.');} \mysqli_set_charset($this->connection, 'utf8'); } diff --git a/log/error_handler/error_handler_dbwriter.php b/log/error_handler/error_handler_dbwriter.php index dff752f..41c6ceb 100644 --- a/log/error_handler/error_handler_dbwriter.php +++ b/log/error_handler/error_handler_dbwriter.php @@ -25,8 +25,6 @@ class error_handler_dbwriter implements \SYSTEM\LOG\error_handler { */ public static function CALL(\Exception $E, $thrown){ try{ - if(\property_exists(get_class($E), 'logged') && $E->logged){ - return false;} //alrdy logged(this prevents proper thrown value for every system exception) $result = \SYSTEM\SQL\SYS_LOG_INSERT::QI(array( get_class($E), $E->getMessage(), $E->getCode(), $E->getFile(), $E->getLine(), $E->getTraceAsString(), getenv('REMOTE_ADDR'),round(microtime(true) - \SYSTEM\time::getStartTime(),5), @@ -34,12 +32,9 @@ class error_handler_dbwriter implements \SYSTEM\LOG\error_handler { array_key_exists('HTTP_REFERER', $_SERVER) ? $_SERVER['HTTP_REFERER'] : null, array_key_exists('HTTP_USER_AGENT',$_SERVER) ? $_SERVER['HTTP_USER_AGENT'] : null, ($user = \SYSTEM\SECURITY\security::getUser()) ? $user->id : null,$thrown ? 1 : 0)); - - if(\property_exists(get_class($E), 'logged')){ - $E->logged = true;} //we just did log + if(!\property_exists(get_class($E), 'do_not_todo_log')){ + \SYSTEM\SAI\saimod_sys_todo::exception($E,false);} } catch (\Exception $E){ - //Dump the Error - echo \SYSTEM\LOG\JsonResult::toString((array)$E); return false;} //Error -> Ignore return false; //We just log and do not handle the error! diff --git a/log/exceptions/DEPRECATED.php b/log/exceptions/DEPRECATED.php index df1b1b6..e252e1a 100644 --- a/log/exceptions/DEPRECATED.php +++ b/log/exceptions/DEPRECATED.php @@ -14,4 +14,4 @@ namespace SYSTEM\LOG; /** * Deprecated Log Class provided by System for marking code as Deprecated. */ -class DEPRECATED extends \SYSTEM\LOG\TODO {} \ No newline at end of file +class DEPRECATED extends \SYSTEM\LOG\SYSTEM_EXCEPTION {} \ No newline at end of file diff --git a/log/exceptions/ERROR.php b/log/exceptions/ERROR.php index 6a1e0ab..5594652 100644 --- a/log/exceptions/ERROR.php +++ b/log/exceptions/ERROR.php @@ -14,4 +14,4 @@ namespace SYSTEM\LOG; /** * Error Log Class provided by System for all kinds of Errors. */ -class ERROR extends \SYSTEM\LOG\TODO {} \ No newline at end of file +class ERROR extends \SYSTEM\LOG\SYSTEM_EXCEPTION {} \ No newline at end of file diff --git a/log/exceptions/INFO.php b/log/exceptions/INFO.php index 232d370..23eaf12 100644 --- a/log/exceptions/INFO.php +++ b/log/exceptions/INFO.php @@ -14,4 +14,7 @@ namespace SYSTEM\LOG; /** * Info Log Class provided by System for logging Infos. */ -class INFO extends \SYSTEM\LOG\SYSTEM_EXCEPTION {} \ No newline at end of file +class INFO extends \SYSTEM\LOG\SYSTEM_EXCEPTION { + /** Property to store if the Exception should not be logged */ + public $do_not_todo_log; +} \ No newline at end of file diff --git a/log/exceptions/SYSTEM_ERROR_EXCEPTION.php b/log/exceptions/SYSTEM_ERROR_EXCEPTION.php index b7c93c1..da12f6b 100644 --- a/log/exceptions/SYSTEM_ERROR_EXCEPTION.php +++ b/log/exceptions/SYSTEM_ERROR_EXCEPTION.php @@ -16,8 +16,6 @@ namespace SYSTEM\LOG; * All other error exception Classes are derived from this. */ class SYSTEM_ERROR_EXCEPTION extends \ErrorException { - /** bool Variable to store if the Exception was logged already */ - public $logged = false; /** * Construct the Error * diff --git a/log/exceptions/SYSTEM_EXCEPTION.php b/log/exceptions/SYSTEM_EXCEPTION.php index 48d41ca..d5ae750 100644 --- a/log/exceptions/SYSTEM_EXCEPTION.php +++ b/log/exceptions/SYSTEM_EXCEPTION.php @@ -15,12 +15,7 @@ namespace SYSTEM\LOG; * System Exception Class provided by System for logging all kinds of System Exceptions. * All other log Classes are derived from this. */ -class SYSTEM_EXCEPTION extends \Exception { - /** bool Variable to store if the Exception was logged already */ - public $logged = false; - /** bool Variable to store if the Exceptions was logged as Todo */ - public $todo_logged = false; - +class SYSTEM_EXCEPTION extends \Exception { /** * Construct the Error * @@ -30,6 +25,7 @@ class SYSTEM_EXCEPTION extends \Exception { */ public function __construct($message = "", $code = 1, $previous = NULL){ parent::__construct($message, $code, $previous); - \SYSTEM\LOG\log::__exception_handler($this,false); + if($previous == NULL){ + error_handler_dbwriter::CALL($this, false);} } } \ No newline at end of file diff --git a/log/exceptions/TODO.php b/log/exceptions/TODO.php index c315334..ea31ff0 100644 --- a/log/exceptions/TODO.php +++ b/log/exceptions/TODO.php @@ -23,6 +23,5 @@ class TODO extends \SYSTEM\LOG\SYSTEM_EXCEPTION { * @param \Exception $previous Previous Error leading to this one. */ public function __construct($message = "", $code = 1, $previous = NULL){ - parent::__construct($message, $code, $previous); - \SYSTEM\SAI\saimod_sys_todo::exception($this,false);} + parent::__construct($message, $code, $previous);} } \ No newline at end of file diff --git a/log/exceptions/WARNING.php b/log/exceptions/WARNING.php index c970c94..989ae08 100644 --- a/log/exceptions/WARNING.php +++ b/log/exceptions/WARNING.php @@ -14,4 +14,4 @@ namespace SYSTEM\LOG; /** * Warning Class provided by System for logging Warnings. */ -class WARNING extends \SYSTEM\LOG\TODO {} \ No newline at end of file +class WARNING extends \SYSTEM\LOG\SYSTEM_EXCEPTION {} \ No newline at end of file