当前位置:   article > 正文

IOS日志记录

IOS日志记录
  1. -(void)CWriteFile:(NSString*)logStr isLogTime:(BOOL)_isLogTime
  2. {
  3. /获取路径
  4. NSString *sandboxPath = NSHomeDirectory();
  5. NSString *documentPath = [sandboxPath stringByAppendingPathComponent:@"Documents"];//将Documents添加到sandbox路径上//
  6. NSString *FileName=[documentPath stringByAppendingPathComponent:@"log.txt"];//fileName就是保存文件的文件名
  7. 获取当前时间
  8. if(_isLogTime)
  9. {
  10. NSDate * nowdate=[NSDate date];
  11. NSDateFormatter *dateformatter=[[NSDateFormatter alloc] init];
  12. [dateformatter setDateFormat:@"YYYY-MM-dd HH:mm:ss"];
  13. NSString * locationString=[dateformatter stringFromDate:nowdate];
  14. logStr = [NSString stringWithFormat:@"%@:%@",locationString,logStr];
  15. [dateformatter release];
  16. }
  17. 写入并关闭
  18. FILE *fp = NULL;
  19. fp = fopen(FileName.cString, "a+" );
  20. if( fp == NULL )
  21. {
  22. return;
  23. }
  24. fprintf( fp, logStr.cString);
  25. fclose( fp);
  26. }

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/知新_RL/article/detail/629881
推荐阅读
相关标签
  

闽ICP备14008679号