Created
September 1, 2016 07:04
-
-
Save liufsd/a0aa8bcb5cd51b718b8c4b63685d407c 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
@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