diff --git a/Classes/SBAppDelegate.m b/Classes/SBAppDelegate.m index 62c838a..2ad4580 100755 --- a/Classes/SBAppDelegate.m +++ b/Classes/SBAppDelegate.m @@ -26,9 +26,17 @@ [SBPrefsController registerUserDefaults]; - NSString *path = [[NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, - NSUserDomainMask, - YES) firstObject] stringByAppendingPathComponent:@"Subler/debugLog.txt"]; + NSString *appSupportPath = [[NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, + NSUserDomainMask, + YES) firstObject] stringByAppendingPathComponent:@"Subler"]; + + if (![[NSFileManager defaultManager] fileExistsAtPath:appSupportPath]) { + [[NSFileManager defaultManager] createDirectoryAtPath:appSupportPath withIntermediateDirectories:YES attributes:nil error:NULL]; + } + + NSString *path = [appSupportPath stringByAppendingPathComponent:@"debugLog.txt"]; + + SBLogger *logger = [[SBLogger alloc] initWithLogFile:[NSURL fileURLWithPath:path]]; [logger clearLog]; diff --git a/Classes/SBLogger.m b/Classes/SBLogger.m index 58ee79c..26b8e13 100644 --- a/Classes/SBLogger.m +++ b/Classes/SBLogger.m @@ -43,8 +43,10 @@ - (void)writeToLog:(NSString *)string { if (self.fileURL) { FILE *f = fopen([[self.fileURL path] fileSystemRepresentation], "a"); - fprintf(f, "%s %s", [[self currentTime] UTF8String], [string UTF8String]); - fclose(f); + if (f) { + fprintf(f, "%s %s", [[self currentTime] UTF8String], [string UTF8String]); + fclose(f); + } } if (self.delegate) {