function write_log($data, $fileName)
{ 
    $month = date('Y-m');
    $dir_name = './Public/log/'.$month.'/';
    $path = $dir_name.$fileName.'_request_log.txt'; 
    
    // 检测目录是否存在,若不存在则进行创建
    if(!file_exists($dir_name))
    {
        $res = mkdir(iconv('UTF-8', 'GBK', $dir_name), 0777, true);
    }
    
    // 以写入方式打开文件
    $fp = fopen($path, 'a');
    
    // 定义写入内容
    $time = '['.date('Y-m-d H:i:s').'] ';
    $text = var_export($data, true);
    
    // 写入并关闭文件
    fwrite($fp, $time.$text."\r\n");
    fclose($fp);
}

 

相关文章:

  • 2021-11-10
  • 2022-01-02
  • 2022-12-23
  • 2021-10-21
  • 2021-11-27
  • 2021-10-25
猜你喜欢
  • 2021-10-12
  • 2021-11-29
  • 2022-12-23
  • 2021-11-21
  • 2022-12-23
  • 2022-02-03
  • 2021-11-26
相关资源
相似解决方案