From 3991ee6af7b42b2b719dd1567153abc178853731 Mon Sep 17 00:00:00 2001 From: sparkyx Date: Thu, 21 May 2026 07:21:07 +0200 Subject: [PATCH] Improve record log --- include/lib/ac_common.php | 143 ++++++++++++++++++++++-------------- scenario/LIB/record_log.php | 8 +- 2 files changed, 96 insertions(+), 55 deletions(-) diff --git a/include/lib/ac_common.php b/include/lib/ac_common.php index 00267e441..d55b62d38 100644 --- a/include/lib/ac_common.php +++ b/include/lib/ac_common.php @@ -1390,7 +1390,7 @@ function is_msie() * Record also the GET and POST data * @param $p_message string message to display */ -function record_log($p_message) +function record_log(...$a_message) { $date= date ('Y-m-d'); // variable: $handle_log resource on log file , @@ -1400,89 +1400,124 @@ function record_log($p_message) { if ( isset ($_SERVER['REMOTE_ADDR']) ) error_log(sprintf("origin %s\n",$_SERVER['REMOTE_ADDR'])); if ( isset ($_SERVER['HTTP_USER_AGENT']) ) error_log(sprintf("agent %s\n",$_SERVER['HTTP_USER_AGENT'])); - if ( gettype ($p_message) == "object" && method_exists($p_message,"getTraceAsString") == 1) { - $exc=$p_message; - do { - error_log("noalyss exception File [".$exc->getFile().":".$exc->getLine()."]",0); - error_log("noalyss exception Message [".$exc->getMessage()."]",0); - error_log("noalyss exception Code [".$exc->getCode()."]",0); - error_log("noalyss exception Trace ".$exc->getTraceAsString(),0); - error_log("------ ",0); - $exc=$exc->getPrevious(); - if ($exc != null )fwrite ($handle_log,"*********************** Previous *********************** \n"); - } while ($exc != null); - } else { - error_log("noalyss".var_export($p_message,true),0); - - } + foreach ($a_message as $p_message ) + { + if ( gettype ($p_message) == "object" && method_exists($p_message,"getTraceAsString") == 1) { + $exc=$p_message; + do { + error_log("noalyss exception File [".$exc->getFile().":".$exc->getLine()."]",0); + error_log("noalyss exception Message [".$exc->getMessage()."]",0); + error_log("noalyss exception Code [".$exc->getCode()."]",0); + error_log("noalyss exception Trace ".$exc->getTraceAsString(),0); + error_log("------ ",0); + $exc=$exc->getPrevious(); + if ($exc != null )fwrite ($handle_log,"*********************** Previous *********************** \n"); + } while ($exc != null); + } elseif ( gettype ($var) == 'object' && get_class($var)=='DOMDocument') + { + $var->formatOutput=true; + error_log("noalyss".$var->saveXML(),0); + } else + error_log("noalyss".var_export($p_message,true),0); + } + error_log("noalyss GET [".json_encode($_GET,0,10)."]"); error_log("_POST [".json_encode($_POST,0,10)."]",0); } else { - if ( isset ($_SERVER['REMOTE_ADDR']) ) fwrite($handle_log,sprintf("origin %s\n",$_SERVER['REMOTE_ADDR'])); - if ( isset ($_SERVER['HTTP_USER_AGENT']) ) fwrite($handle_log,sprintf("agent %s\n",$_SERVER['HTTP_USER_AGENT'])); - - if ( gettype ($p_message) == "object" && method_exists($p_message,"getTraceAsString") == 1) { + foreach ($a_message as $p_message ) + { + /** + * write in syslog + */ + if ( gettype ($p_message) == "object" && method_exists($p_message,"getTraceAsString") == 1) { - error_log("noalyss exception ".$p_message->getMessage(),0); - error_log("noalyss exception".$p_message->getTraceAsString(),0); - } else { - error_log("noalyss".var_export($p_message,true),0); + error_log("noalyss exception ".$p_message->getMessage(),0); + error_log("noalyss exception".$p_message->getTraceAsString(),0); + } else { + error_log("noalyss".var_export($p_message,true),0); + } } $now=date ('Y-m-d H:i:s'); fwrite ($handle_log,str_repeat("=", 80)."\n"); + if ( isset ($_SERVER['REMOTE_ADDR']) ) fwrite($handle_log,sprintf("origin %s\n",$_SERVER['REMOTE_ADDR'])); + if ( isset ($_SERVER['HTTP_USER_AGENT']) ) fwrite($handle_log,sprintf("agent %s\n",$_SERVER['HTTP_USER_AGENT'])); + fwrite ($handle_log,"ERROR: {$now}\n"); fwrite($handle_log,"noalyss GET [".var_export($_GET,true)."]"); fwrite ($handle_log,"\n"); fwrite($handle_log,"_POST [".var_export($_POST,true)."]"); fwrite ($handle_log,"\n"); - if ( gettype ($p_message) == "object" && method_exists($p_message,"getTraceAsString") == 1) { - $exc=$p_message; - do { - fwrite($handle_log,"noalyss exception File [".$exc->getFile().":".$exc->getLine()."]"); + foreach ($a_message as $p_message) + { + if ( gettype ($p_message) == "object" && method_exists($p_message,"getTraceAsString") == 1) { + $exc=$p_message; + do { + fwrite($handle_log,"noalyss exception File [".$exc->getFile().":".$exc->getLine()."]"); + fwrite ($handle_log,"\n"); + fwrite($handle_log,"noalyss exception Message [".$exc->getMessage()."]"); + fwrite ($handle_log,"\n"); + fwrite($handle_log,"noalyss exception Code [".$exc->getCode()."]"); + fwrite ($handle_log,"\n"); + fwrite($handle_log,"noalyss exception Trace \n".$exc->getTraceAsString()); + fwrite ($handle_log,"\n"); + $exc=$exc->getPrevious(); + if ($exc != null )fwrite ($handle_log,"*********************** Previous *********************** \n"); + } while ($exc != null); + } elseif ( gettype ($var) == 'object' && get_class($var)=='DOMDocument') + { + $var->formatOutput=true; + $output.=$var->saveXML() .PHP_EOL; + } else { + fwrite($handle_log,"noalyss".var_export($p_message,true)); fwrite ($handle_log,"\n"); - fwrite($handle_log,"noalyss exception Message [".$exc->getMessage()."]"); - fwrite ($handle_log,"\n"); - fwrite($handle_log,"noalyss exception Code [".$exc->getCode()."]"); - fwrite ($handle_log,"\n"); - fwrite($handle_log,"noalyss exception Trace \n".$exc->getTraceAsString()); - fwrite ($handle_log,"\n"); - $exc=$exc->getPrevious(); - if ($exc != null )fwrite ($handle_log,"*********************** Previous *********************** \n"); - } while ($exc != null); - } else { - fwrite($handle_log,"noalyss".var_export($p_message,true)); - fwrite ($handle_log,"\n"); - + + } } - + fwrite ($handle_log,str_repeat("=", 80)."\n"); fclose($handle_log); } + } if(!function_exists('tracedebug')) { - function tracedebug($file,$var, $label = NULL) { + function tracedebug($file,...$a_var) { $tmp_file = sys_get_temp_dir().DIRECTORY_SEPARATOR.$file; $file_loginput=fopen( $tmp_file,'a+'); if ( $file_loginput == false) { return;} $output = ''; $output .= date('d-m-y H:i'); - if(!is_null($label)) { - $output .= $label . ': '; - } - if ( gettype ($var) == 'object' && get_class($var)=='DOMDocument') + foreach ($a_var as $var) { - $var->formatOutput=true; - $output.=$var->saveXML() .PHP_EOL; - } else - { - $output .= print_r($var, 1) . PHP_EOL; + if ( gettype ($var) == "object" && method_exists($var,"getTraceAsString") == 1) { + $exc=$var; + do { + fwrite($file_loginput,"noalyss exception File [".$exc->getFile().":".$exc->getLine()."]"); + fwrite ($file_loginput,"\n"); + fwrite($file_loginput,"noalyss exception Message [".$exc->getMessage()."]"); + fwrite ($file_loginput,"\n"); + fwrite($file_loginput,"noalyss exception Code [".$exc->getCode()."]"); + fwrite ($file_loginput,"\n"); + fwrite($file_loginput,"noalyss exception Trace \n".$exc->getTraceAsString()); + fwrite ($file_loginput,"\n"); + $exc=$exc->getPrevious(); + if ($exc != null )fwrite ($file_loginput,"*********************** Previous *********************** \n"); + } while ($exc != null); + }elseif ( gettype ($var) == 'object' && get_class($var)=='DOMDocument') + { + $var->formatOutput=true; + $output.=$var->saveXML() .PHP_EOL; + } else + { + $output .= print_r($var, 1) . PHP_EOL; + } + $output.= str_repeat("-", 80); + $output.="\n"; } - file_put_contents($tmp_file, $output, FILE_APPEND); } } @@ -2053,4 +2088,4 @@ function convert_array_select($array) $i++; } return $a_ret; -} \ No newline at end of file +} diff --git a/scenario/LIB/record_log.php b/scenario/LIB/record_log.php index b6099f059..fe64ae617 100644 --- a/scenario/LIB/record_log.php +++ b/scenario/LIB/record_log.php @@ -42,7 +42,13 @@ function x() try { x(); + } catch (\Exception $e) { record_log($e); - +tracedebug("log",$e); } + printf("tracedebug in sys_get_temp_dir() = %s", sys_get_temp_dir()); +?> +

+ Check file in noalyss/log +