dongtan2017 2017-02-13 20:22
浏览 42
已采纳

如何记录不支持日志的托管错误?

I want to log errors to a file using this method:

$tpath = "/storage/my-errors.log";
error_log("You messed up!", 3, $tpath);

I have set permissions on the path to 777 and it should save this value "You messed up!" into the file, but I can't figure it out.

I made an error myself, but it did not get saved in the log file, just messaged "You messed up!"!

I also tried:

ini_set("log_errors", 1);
ini_set("error_log", "mypath");
error_log( "Hello, errors!" );
  • 写回答

1条回答 默认 最新

  • doumigu9594 2017-02-13 21:31
    关注

    You can log using your desired method into a CSV.

    Create a re-usable function which will control all your logging:

    function logger($log_name, $log_message){
    
      $todays_date = date('Y-m-d');
    
      // Open the file to write to it, file is created if it does not exist.
      $output = fopen($log_name."-".$todays_date.".csv", 'w');
    
      // Write line of log in CSV format to the log.
      fputcsv($output, array("[".$todays_date."] ",$log_message));
    
      // Close the file.
      fclose($output);
    }
    

    You can use this with your process names as the $log_name.

    Example

    logger("user_login", "You messed up");
    

    This would produce a log called user_login-2017-02-13.csv. The file will be created if it does not exist, and subsequent writes to the file will be appended line by line.

    The date part is there to automatically make a new file for each day, so you can alter that to your needs.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么