Created
July 10, 2012 06:30
-
-
Save siqin/3081582 to your computer and use it in GitHub Desktop.
log of objective-c
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
#pragma mark - | |
#define DEFAULT_LOG_FILENAME @"log.log" | |
- (void)log:(NSString *)log | |
{ | |
#ifdef DEBUG | |
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); | |
NSString *baseDir = ([paths count] > 0) ? [paths objectAtIndex:0] : nil; | |
NSString *logPath = [baseDir stringByAppendingPathComponent:DEFAULT_LOG_FILENAME]; | |
// dispatch_once needed ? | |
if (![[NSFileManager defaultManager] fileExistsAtPath:logPath]) { | |
[[NSFileManager defaultManager] createFileAtPath:logPath contents:nil attributes:nil]; | |
} | |
FILE *file = fopen([logPath UTF8String], "ab"); | |
fwrite([log UTF8String], strlen([log UTF8String]), 1, file); | |
fclose(file); | |
#endif | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment