Redirect NSLog()

Does anyone know how to redirect NSLog() output? So far, the output goes into XCode's run log window. I would like to redirect it to a text file…
#import
#import

static int stderrwrite(void *inFD, const char *buffer, int size)
{
printf("%s",buffer) ;
fflush(stdout) ;
return size ;
}


int main (int argc, char **argv)
{

NSLog(@"Pure NSLog") ;

fprintf(stderr, "fprintf stderrn") ;

freopen("tmpstderr", "a", stderr) ;
fprintf(stderr, "fprintf stderr after reopenn") ;
fflush(stderr) ;

stderr->_write = stderrwrite ;
fprintf(stderr, "fprintf stderr after stderr->_write patchn") ;

return 0 ;
}
Compile and test with:
$ cc -o redirectNSLog -framework Foundation redirectNSLog.m
$ ./redirectNSLog > stdout 2> stderr
$ cat stdout
fprintf stderr after stderr->_write patch
$ cat stderr
2006-05-07 10:30:11.191 redirectNSLog[25287] Pure NSLog
fprintf stderr
$ cat tmpstderr
fprintf stderr after reopen
Note that the method using stderr->_write allows easy redirection in a NSTextView, just be aware that inside the stderrwrite function there is no NSAutoReleasePool active, so either don't allocate memory with functions expecting an autoreleased pool or allocate one locally. And also be carefull with multi-threaded code when accessing global variables inside that routine.