iOS 保存打印的log日志

有些时候测试,需要通过log日志来调式代码,发现问题
可以将打印的log日志保存在APP本地文件中

 //Save NSlog print information to a file in the Document directory
- (void)redirectNSlogToDocumentFolder{
    UIDevice *device = [UIDevice currentDevice];
    if ([[device model] isEqualToString:@"Simulator"]) {
        return;
    }

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

    NSString *documentDirectory = [paths objectAtIndex:0];

    NSString *fileName = [NSString stringWithFormat:@"test.log"];

    NSString *logFilePath = [documentDirectory stringByAppendingPathComponent:fileName];

    // Delete existing files
    NSFileManager *defaultManager = [NSFileManager defaultManager];
    [defaultManager removeItemAtPath:logFilePath error:nil];

    //Enter the log into the file
    freopen([logFilePath cStringUsingEncoding:NSASCIIStringEncoding], "a+", stdout);
    freopen([logFilePath cStringUsingEncoding:NSASCIIStringEncoding], "a+", stderr);

}

通过iTunes下载log文件


保存log日志.png
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • iTunes iTunes是由苹果公司开发的媒体播放器,媒体库,在线广播电台和移动设备管理应用程序。它用于播放,下...
    dweet阅读 1,959评论 0 0
  • ORA-00001: 违反唯一约束条件 (.) 错误说明:当在唯一索引所对应的列上键入重复值时,会触发此异常。 O...
    我想起个好名字阅读 6,132评论 0 9
  • 小家伙仍旧没有上课的一天。 早晨起来前,一阵咳嗽好久,拍拍他才继续睡着。 血液化验的结果已经出来一张,除了支气管炎...
    小宇宙要强大阅读 189评论 0 0
  • 开心常常,很多时候跟胜宝想不到话说了,他妈要回来也不知道真正回来的原因。工作的事还没确定,现在的要是就是找工作。其...
    Fineyoga瑾璟阅读 233评论 0 0

友情链接更多精彩内容