注意:日志文件要给绝对路径,如果是相对路径,即使给777权限也没用。
/**
* 记录日志
* @param $content
* @param string $file
*/
function my_logger($content,$file="log.txt") {
$content = json_encode($content,JSON_UNESCAPED_UNICODE);
$base_path = rtrim($_SERVER['DOCUMENT_ROOT'],'/')."/项目目录/logs/";
$myfile = $base_path.$file;
//echo $myfile;
$times = date('Y-m-d H:i:s', time());
$string = $times.'======>'.$content."\n\r";
file_put_contents($myfile, $string , FILE_APPEND);
}