xcode重定向log到本地问题

    xiaoxiao2021-03-28  26

    使用前需要在plist中设置日志共享

    在info.plist中打开Application supports iTunes file sharing

    - (void)redirectNSlogToDocumentFolder { NSLog(@"Log重定向到本地,如果您需要控制台Log,注释掉重定向逻辑即可。"); NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentDirectory = [paths objectAtIndex:0]; NSDate *currentDate = [NSDate date]; NSDateFormatter *dateformatter = [[NSDateFormatter alloc] init]; [dateformatter setDateFormat:@"MMddHHmmss"]; NSString *formattedDate = [dateformatter stringFromDate:currentDate]; NSString *fileName = [NSString stringWithFormat:@"rc%@.log", formattedDate]; NSString *logFilePath = [documentDirectory stringByAppendingPathComponent:fileName]; freopen([logFilePath cStringUsingEncoding:NSASCIIStringEncoding], "a+", stdout); freopen([logFilePath cStringUsingEncoding:NSASCIIStringEncoding], "a+", stderr); }

    转载请注明原文地址: https://ju.6miu.com/read-664592.html

    最新回复(0)