Created
December 11, 2010 16:47
-
-
Save st3fan/737457 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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