xcode重定向log到本地问题

来源:互联网 发布:微信显示无法连接网络 编辑:程序博客网 时间:2024/06/05 21:48

使用前需要在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);}


0 0
原创粉丝点击