How to escape a recursive process of saving error log of a database - PHP?

0

I have a class that saves the log in a database based on any transaction error in that database.

The fact is that the process of saving this log tbm is a transaction and in a hypothetical scenario any process could generate an error, and then this process would trigger the process of saving the error and this new process would also generate an error calling himself. This process would have no end.

Here is the catch code:

 catch (PDOException $e) {     
                self::$exceptionObjc = $e;  
                self::saveLogMsgInDb(["exceptionObjc"=>self::$exceptionObjc,"sql"=>self::$sql]);
                self::$arrCatchConnResult = self::saveLogMsg(["exceptionObjc"=>self::$exceptionObjc,"sql"=>self::$sql]);
                self::$conn = null;
                if (self::$die) {
                    $msg = self::$arrCatchConnResult["displayMsgHTML"];
                    die($msg);
                }
            }

Here is the saveLogInDB code:

public static function saveLogMsgInDb($saveLogsParam = NULL) {              

       $excepObjc = $saveLogsParam['exceptionObjc'] ;

       $sql = $saveLogsParam['sql'];
       $logMsg = $excepObjc->getMessage();   
       $StackTrace = json_encode($excepObjc->getTrace());  
       $exceptionObjc = json_encode($excepObjc);  
       //$StackTrace = addslashes(json_encode($excepObjc->getTrace()));  
       //$exceptionObjc = addslashes(json_encode($excepObjc)); 

        $arrSql=[
            "db_Logs"=>[
                     "msg"=>[$logMsg,PDO::PARAM_STR], 
                     "sql"=>[$sql,PDO::PARAM_STR],           
                     "StackTrace"=>[$StackTrace,PDO::PARAM_STR],
                     "exceptionObjc"=>[$exceptionObjc,PDO::PARAM_STR]
            ]
        ];



        self::set_values($arrSql); 
        //die();

    }

One possible solution would be to use a die() inside saveLogMsgInDb () but this would cause the site to stop.

My question is what would be an approach that escaped this recursive process without breaking the web site process?

    
asked by anonymous 17.05.2017 / 20:06

0 answers