Skip to content

Instantly share code, notes, and snippets.

@st3fan
Created December 11, 2010 16:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save st3fan/737457 to your computer and use it in GitHub Desktop.
Save st3fan/737457 to your computer and use it in GitHub Desktop.
int main(int argc, char *argv[])
{
int retVal = 0;
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
{
#if YOURAPP_DEBUG_LOG
// Redirect stdout to a file in ~/Documents
NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
[dateFormatter setDateFormat: @"yyyyMMd-Hms"];
NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
if (paths && [paths count] != 0) {
NSString* path = [[paths objectAtIndex: 0] stringByAppendingPathComponent:
[NSString stringWithFormat: @"/YourApp-%@.txt", [dateFormatter stringFromDate: [NSDate date]]]];
if ([[NSFileManager defaultManager] createFileAtPath: path contents: [NSData data] attributes: nil] == NO) {
NSLog(@"Could create %@: %s", path, strerror(errno));
} else {
NSFileHandle* fileHandle = [NSFileHandle fileHandleForWritingAtPath: path];
if (fileHandle != nil) {
if (dup2([fileHandle fileDescriptor], STDERR_FILENO) == -1) {
NSLog(@"Unable to redirect stderr to %@: %s", path, strerror(errno));
} else {
NSLog(@"This is the start of the log file for Your App");
}
}
}
}
#endif
// Start the application
retVal = UIApplicationMain(argc, argv, nil, nil);
}
[pool release];
return retVal;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment