Skip to content

Instantly share code, notes, and snippets.

@liufsd
Created September 1, 2016 07:04
Show Gist options
  • Select an option

  • Save liufsd/a0aa8bcb5cd51b718b8c4b63685d407c to your computer and use it in GitHub Desktop.

Select an option

Save liufsd/a0aa8bcb5cd51b718b8c4b63685d407c to your computer and use it in GitHub Desktop.

Revisions

  1. liufsd created this gist Sep 1, 2016.
    21 changes: 21 additions & 0 deletions LogProvider.m
    Original 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