前言
在线上接口需要调试但是又不能输出到前台的情况下,我们需要打印文件日志。
简单输出
$file=dirname(__FILE__).'/log.txt';
file_put_contents($file, $data."\n",FILE_APPEND);//注意file_put_contents会创建文件,但是不会创建目录,如果你的日志输出位置在不存在的目录,需要mkdir
#数组输出
$fp = fopen(dirname(__FILE__).'/log.txt', 'a+b');
fwrite($fp, var_export($data, true));
fwrite($fp, var_export($data2, true));
fclose($fp);