Improve record log
This commit is contained in:
parent
552a980182
commit
3991ee6af7
2 changed files with 96 additions and 55 deletions
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue