title: How to redirect the nslog output to file instead of console
body: <p>I have cocoa application running on OS X. I have used NSLog for debugging purpose. Now I want to redirect the log statements to file instead of console.</p>
  
  <p>I have used this method but it results logging in Console as well as in file.</p>
  
  <pre><code>- (BOOL)redirectNSLog
  {
      // Create log file
      [@"" writeToFile:@"/NSLog.txt" atomically:YES encoding:NSUTF8StringEncoding error:nil];
      id fileHandle = [NSFileHandle fileHandleForWritingAtPath:@"/NSLog.txt"];
      if (!fileHandle)    return NSLog(@"Opening log failed"), NO;
      [fileHandle retain];
  
      // Redirect stderr
      int err = dup2([fileHandle fileDescriptor], STDERR_FILENO);
      if (!err)   return  NSLog(@"Couldn't redirect stderr"), NO;
  
      return  YES;
  }
  </code></pre>
  
  <p>Is it possible to not have log statement in console but only in file ??</p>