Created
September 1, 2016 07:04
-
-
Save liufsd/a0aa8bcb5cd51b718b8c4b63685d407c to your computer and use it in GitHub Desktop.
Revisions
-
liufsd created this gist
Sep 1, 2016 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,21 @@ @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