Thursday, 4 July 2013

Redirect NSLog to file.

#pragma mark- Redirect NSLog to file-

+ (void)redirectNSLogToDocumentFolder
{
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
    
    NSString *documentsDirectory = [paths objectAtIndex:0];
    
    NSString *fileName =[NSString stringWithFormat:@"NSLogFile"];
    
    NSString *logFilePath = [documentsDirectory stringByAppendingPathComponent:fileName];
    
    NSLog(@"Redirecting NSLog to file");
    freopen([logFilePath cStringUsingEncoding:NSASCIIStringEncoding],"a+",stderr);
    

}

No comments:

Post a Comment