function loog($string = "",$show_tp_info = false,$ignore_app_debug=false){
if (APP_DEBUG||$ignore_app_debug) {
//echo RUNTIME_PATH."Logs/".MODULE_NAME."/log.txt";
if (!is_dir(RUNTIME_PATH."Logs/".MODULE_NAME)) {
mkdir(RUNTIME_PATH."Logs/".MODULE_NAME);
}
$myfile = fopen(RUNTIME_PATH."Logs/".MODULE_NAME."/log.txt", "a") or die("Unable to open file!");
$data = debug_backtrace();//获取debug信息。
$txt = "#".$data[0][‘line‘]." @".$data[1][‘function‘] ." @". basename($data[0][‘file‘]).
" " .date("H:i:s");
$txt .= $show_tp_info?" TP:".MODULE_NAME."=>".CONTROLLER_NAME."=>".ACTION_NAME."\n ":"\n ";
$txt .= ($string!="")? is_string($string)? ($string == "@ft")?"full trace:\n".json_encode($data, JSON_UNESCAPED_UNICODE|JSON_PRETTY_PRINT)
:"var: ".$string
: "block:\n".json_encode($string, JSON_UNESCAPED_UNICODE|JSON_PRETTY_PRINT)
: "无限空";
$txt .= "\n\n********************************************************************".
"*********************************************************************\n\n";
fwrite($myfile, $txt);
fclose($myfile);
}
}
原文:https://www.cnblogs.com/qiaochaoyu/p/11652037.html