Last active
August 29, 2015 13:55
-
-
Save osmszk/8726500 to your computer and use it in GitHub Desktop.
Write console log as File output
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
+ (NSString*)consoleLogFileWithDate | |
{ | |
NSDateFormatter *inputDateFormatter = [[NSDateFormatter alloc] init]; | |
[inputDateFormatter setDateFormat:@"yyyyMMddHHmmss"]; | |
[inputDateFormatter setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"US"]]; | |
NSString *dateStr = [inputDateFormatter stringFromDate:[NSDate date]]; | |
return [NSString stringWithFormat:@"console%@.log",dateStr]; | |
} | |
static FILE *consoleLog; | |
- (void)writeToFileConsoleLog | |
{ | |
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES); | |
NSString *documentsDirectory = [paths objectAtIndex:0]; | |
NSString *oldConsoleFilename = CONSOLELOG_OLD_FILE; | |
NSString *lastConsoleFilename = [self consoleLogFileWithDate];//CONSOLELOG_FILE; | |
NSString *path = [documentsDirectory stringByAppendingPathComponent:oldConsoleFilename]; | |
NSString *lastPath = [documentsDirectory stringByAppendingPathComponent:lastConsoleFilename]; | |
NSError *err; | |
[[NSFileManager defaultManager] removeItemAtPath:path error:&err ]; | |
[[NSFileManager defaultManager] moveItemAtPath:lastPath toPath:path error:&err ]; | |
consoleLog = freopen([lastPath cStringUsingEncoding:NSASCIIStringEncoding], "w", stderr); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment