function debug(){ $num_args = func_num_args(); //实参个数 $arg_list = func_get_args(); //返回某一个实参,必须是实参数组的索引; for($i=0;$i<$num_args;$i++){ echo "第 $i 个变量的值为:".$arg_list[$i]."<br>"; } echo "当前所处的文件名为:".__FILE__."<br><br>"; }
function writeLog($data, $flag = false) { $date = date("Ymd", time()); $path = "/home/xxx/debug_logs/log_{$date}.txt"; if (is_array($data) || is_object($data)) { $data = " " . print_r($data, 1); } $backtrace = debug_backtrace()[0]; $file = str_replace('/home/renxing/git/', '', $backtrace['file']); $line = $backtrace['line']; $content = date("Y-m-d H:i:s") . "|" . $file . "|" . $line . "|" . $data; if ($flag) { $content .= "|*****" . json_encode(debug_backtrace(), JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) . "*****|"; } $content .= " "; file_put_contents($path, $content, FILE_APPEND); }