Skip to content

Instantly share code, notes, and snippets.

@liufsd
Created September 1, 2016 07:04
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 liufsd/a0aa8bcb5cd51b718b8c4b63685d407c to your computer and use it in GitHub Desktop.
Save liufsd/a0aa8bcb5cd51b718b8c4b63685d407c to your computer and use it in GitHub Desktop.
@implementation LogProvider
+(void)writeLogFile:(NSString* )message {
NSString *applicationCacheDirectory = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) lastObject];
NSDateFormatter* formate = [[NSDateFormatter alloc] init];
[formate setDateFormat:@"yyyy-MM-dd"];
NSString* logFolder = [applicationCacheDirectory stringByAppendingPathComponent:@"SKPhotoCloudUploadLog"];
NSString* finalPath = [logFolder stringByAppendingPathComponent: [NSString stringWithFormat:@"%@.log",[formate stringFromDate:[NSDate new]]]];
NSFileHandle *output = [NSFileHandle fileHandleForWritingAtPath:finalPath];
if(output == nil) {
if (![[NSFileManager defaultManager] fileExistsAtPath:logFolder]) {
[[NSFileManager defaultManager] createDirectoryAtPath:logFolder withIntermediateDirectories:YES attributes:nil error:Nil];
}
[[NSFileManager defaultManager] createFileAtPath:finalPath contents:nil attributes:nil];
output = [NSFileHandle fileHandleForWritingAtPath:finalPath];
} else {
[output seekToEndOfFile];
}
[output writeData:[[NSString stringWithFormat:@"%@\r\n", message] dataUsingEncoding:NSUTF8StringEncoding]];
[output closeFile];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment