Skip to content
Browse files

Add, and use, DLog

  • Loading branch information...
1 parent 201a7a0 commit 5450904e02135ac257c813287e9b9e115130a3f3 Brian Cooke committed Jan 23, 2012
View
16 Clone.xcodeproj/project.pbxproj
@@ -13,6 +13,7 @@
D6278D6A14C05B6E00CD37A4 /* Credits.rtf in Resources */ = {isa = PBXBuildFile; fileRef = D6278D6814C05B6E00CD37A4 /* Credits.rtf */; };
D6278D6D14C05B6E00CD37A4 /* RSCAppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = D6278D6C14C05B6E00CD37A4 /* RSCAppDelegate.m */; };
D6278D7014C05B6E00CD37A4 /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = D6278D6E14C05B6E00CD37A4 /* MainMenu.xib */; };
+ D671529514CD9CB90012024C /* NSDate+Format.m in Sources */ = {isa = PBXBuildFile; fileRef = D671529414CD9CB90012024C /* NSDate+Format.m */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; };
D6DFC16214C0629700CE3F27 /* RSCGitCloner.m in Sources */ = {isa = PBXBuildFile; fileRef = D6DFC16114C0629700CE3F27 /* RSCGitCloner.m */; };
D6DFC16714C0849000CE3F27 /* RSCSettings.m in Sources */ = {isa = PBXBuildFile; fileRef = D6DFC16614C0849000CE3F27 /* RSCSettings.m */; };
/* End PBXBuildFile section */
@@ -43,6 +44,9 @@
D6278D6B14C05B6E00CD37A4 /* RSCAppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RSCAppDelegate.h; sourceTree = "<group>"; };
D6278D6C14C05B6E00CD37A4 /* RSCAppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RSCAppDelegate.m; sourceTree = "<group>"; };
D6278D6F14C05B6E00CD37A4 /* en */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = en; path = en.lproj/MainMenu.xib; sourceTree = "<group>"; };
+ D671529214CD9CB90012024C /* DLog.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DLog.h; sourceTree = "<group>"; };
+ D671529314CD9CB90012024C /* NSDate+Format.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSDate+Format.h"; sourceTree = "<group>"; };
+ D671529414CD9CB90012024C /* NSDate+Format.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSDate+Format.m"; sourceTree = "<group>"; };
D6C7609614C31B2C00D4C259 /* Cloner.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.xml; path = Cloner.entitlements; sourceTree = "<group>"; };
D6DFC16014C0629700CE3F27 /* RSCGitCloner.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = RSCGitCloner.h; path = Models/RSCGitCloner.h; sourceTree = "<group>"; };
D6DFC16114C0629700CE3F27 /* RSCGitCloner.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = RSCGitCloner.m; path = Models/RSCGitCloner.m; sourceTree = "<group>"; };
@@ -137,9 +141,20 @@
name = Models;
sourceTree = "<group>";
};
+ D671529114CD9CB90012024C /* DLog */ = {
+ isa = PBXGroup;
+ children = (
+ D671529214CD9CB90012024C /* DLog.h */,
+ D671529314CD9CB90012024C /* NSDate+Format.h */,
+ D671529414CD9CB90012024C /* NSDate+Format.m */,
+ );
+ path = DLog;
+ sourceTree = "<group>";
+ };
D6DFC14914C05EF600CE3F27 /* Ext */ = {
isa = PBXGroup;
children = (
+ D671529114CD9CB90012024C /* DLog */,
);
name = Ext;
path = ext;
@@ -214,6 +229,7 @@
D6278D6D14C05B6E00CD37A4 /* RSCAppDelegate.m in Sources */,
D6DFC16214C0629700CE3F27 /* RSCGitCloner.m in Sources */,
D6DFC16714C0849000CE3F27 /* RSCSettings.m in Sources */,
+ D671529514CD9CB90012024C /* NSDate+Format.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
View
1 Clone/Clone-Prefix.pch
@@ -5,4 +5,5 @@
#ifdef __OBJC__
#import <Cocoa/Cocoa.h>
#import "RSCConstants.h"
+ #import "DLog.h"
#endif
View
5 Clone/Models/RSCGitCloner.m
@@ -50,7 +50,7 @@ - (void) clone
NSString *repoName = [[self.repositoryURL lastPathComponent] stringByDeletingPathExtension];
self.destinationPath = [NSString stringWithFormat:@"%@/%@", [RSC_SETTINGS destinationPath], repoName];
- NSLog(@"Cloning %@ to %@", self.repositoryURL, self.destinationPath);
+ DLog(@"Cloning %@ to %@", self.repositoryURL, self.destinationPath);
NSTask *task = [[NSTask alloc] init];
task.launchPath = @"/usr/bin/git";
@@ -78,7 +78,7 @@ - (void) clone
NSData *readData = [file availableData];
NSString *response = [[NSString alloc] initWithData:readData encoding:NSUTF8StringEncoding];
- NSLog(@"%@", response);
+ DLog(@"%@", response);
// check for username prompt
NSUInteger numberOfMatches = [usernameRegex numberOfMatchesInString:response options:0 range:NSMakeRange(0, [response length])];
@@ -87,6 +87,7 @@ - (void) clone
// prompting for username and password - kill the task and prompt the user
self.didTerminate = YES;
[task terminate];
+ [task waitUntilExit];
self.completionBlock(kRSCGitClonerErrorAuthenticationRequired);
return;
}
View
6 Clone/RSCAppDelegate.m
@@ -74,21 +74,21 @@ - (IBAction)clone:(id)sender
RSCGitCloner *cloner = [[RSCGitCloner alloc] initWithRepositoryURL:repoURL];
void (^cloneProgressBlock)(NSInteger progress) = ^(NSInteger progress) {
- NSLog(@"Progress!: %lu", progress);
+ DLog(@"Progress!: %lu", progress);
[self.progressBar setIndeterminate:NO];
[self.progressBar setDoubleValue:progress];
};
void (^cloneCompletionBlock)(NSInteger responseCode) = ^(NSInteger responseCode) {
- NSLog(@"Completion block...");
+ DLog(@"Completion block...");
[self.progressBar setDoubleValue:0.0];
[self.progressBar stopAnimation:self];
if (responseCode == kRSCGitClonerErrorNone) {
[[NSWorkspace sharedWorkspace] openFile:cloner.destinationPath];
} else if (responseCode == kRSCGitClonerErrorAuthenticationRequired) {
- NSLog(@"Prompt for username and password!");
+ DLog(@"Prompt for username and password!");
// just nuke the destination path.
// TODO: Make sure it's empty?
View
24 ext/DLog/DLog.h
@@ -0,0 +1,24 @@
+
+#ifndef Ringtones_DLog_h
+#define Ringtones_DLog_h
+
+#import "NSDate+Format.h"
+
+#define CLog(...) (void)printf("%s %s\n", [[[NSDate date] consoleDateString] UTF8String], [[NSString stringWithFormat:__VA_ARGS__] UTF8String])
+
+// Almost a drop-in replacement for NSLog
+// DLog();
+// DLog(@"value: %d", x);
+// Unfortunately this doesn't work DLog(aStringVariable);
+// You have to do this instead DLog(@"%@", aStringVariable);
+#ifdef DEBUG
+#define DLog(fmt, ...) CLog((@"%s Line %d: " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);
+#define ALog(fmt, ...) CLog((@"%s Line %d: " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);
+#else
+#define DLog(...) // ALog always displays output regardless of the DEBUG setting
+#define ALog(fmt, ...) NSLog((@"%s[%d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);
+#define DAlert(...)
+#define NS_BLOCK_ASSERTIONS // Don't raise assertions in production
+#endif
+
+#endif
View
14 ext/DLog/NSDate+Format.h
@@ -0,0 +1,14 @@
+
+@interface NSDate(Format)
+
++(NSDateFormatter*) rfc822Formatter;
++(NSDate*) dateFromRFC822:(NSString*)date;
+
++(NSDate *) dateFromRFC1123String: (NSString *) dateString;
+
+-(NSString*) descriptionWithFormat:(NSString*)stringFormat timeZone:(NSString*)aZone locale:(NSString*)aLocale;
+-(NSString*) descriptionWithFormat:(NSString *)stringFormat;
+-(NSString*) consoleDateString;
+-(NSString*) rfc822DateString;
+
+@end
View
92 ext/DLog/NSDate+Format.m
@@ -0,0 +1,92 @@
+//
+// Extention to allow simple date formatting for
+// applications such as printing to the console.
+//
+// Formatting References:
+// http://developer.apple.com/documentation/Darwin/Reference/ManPages/man3/strftime.3.html
+// http://www.stepcase.com/blog/2008/12/02/format-string-for-the-iphone-nsdateformatter/
+//
+
+#import "NSDate+Format.h"
+
+static NSDateFormatter *__rfc822Formatter = nil;
+static NSDateFormatter *__rfc1123Formatter = nil;
+
+
+@implementation NSDate (Format)
+
++(NSDateFormatter*) rfc822Formatter
+{
+ if (!__rfc822Formatter) {
+ __rfc822Formatter = [[NSDateFormatter alloc] init];
+ NSLocale *enUS = [[[NSLocale alloc] initWithLocaleIdentifier:@"en_US"] autorelease];
+ [__rfc822Formatter setLocale: enUS];
+ [__rfc822Formatter setDateFormat:@"EEE, dd MMM yyyy HH:mm:ss z"];
+ }
+ return __rfc822Formatter;
+}
+
+
++(NSDate*) dateFromRFC822:(NSString*)date
+{
+ return [[self rfc822Formatter] dateFromString: date];
+}
+
+
++(NSDateFormatter *) rfc1123Formatter
+{
+ if (!__rfc1123Formatter) {
+ __rfc1123Formatter = [[NSDateFormatter alloc] init];
+ NSLocale *enUS = [[[NSLocale alloc] initWithLocaleIdentifier:@"en_US"] autorelease];
+ [__rfc1123Formatter setLocale: enUS];
+ [__rfc1123Formatter setDateFormat:@"EEE, dd MMM yyyy HH:mm:ss z"];
+ }
+ return __rfc1123Formatter;
+}
+
+
++(NSDate *) dateFromRFC1123String: (NSString *) string
+{
+ NSDateFormatter *formatter = [self rfc1123Formatter];
+
+ // Does the string include a week day?
+ NSString *day = @"";
+ if ([string rangeOfString:@","].location != NSNotFound) {
+ day = @"EEE, ";
+ }
+ // Does the string include seconds?
+ NSString *seconds = @"";
+ if ([[string componentsSeparatedByString:@":"] count] == 3) {
+ seconds = @":ss";
+ }
+ [formatter setDateFormat:[NSString stringWithFormat:@"%@dd MMM yyyy HH:mm%@ z",day,seconds]];
+ return [formatter dateFromString:string];
+}
+
+
+-(NSString*) descriptionWithFormat:(NSString*)stringFormat timeZone:(NSString*)aZone locale:(NSString*)aLocale
+{
+ NSDateFormatter *formatter = [[[NSDateFormatter alloc] init] autorelease];
+ [formatter setDateFormat:stringFormat];
+ return [formatter stringFromDate:self];
+}
+
+
+-(NSString*) descriptionWithFormat:(NSString *)stringFormat
+{
+ return [self descriptionWithFormat:stringFormat timeZone:nil locale:nil];
+}
+
+
+-(NSString*) rfc822DateString
+{
+ return [self descriptionWithFormat:@"dd MMM yyyy HH:mm:ss z" timeZone:nil locale:nil];
+}
+
+
+-(NSString*) consoleDateString
+{
+ return [self descriptionWithFormat:@"yyyy-MM-dd HH:mm:ss.SSS" timeZone:nil locale:nil];
+}
+
+@end

0 comments on commit 5450904

Please sign in to comment.
Something went wrong with that request. Please try again.