Added optional logging for debugging help

Activate using [[BWQuincyManager sharedQuincyManager] setLoggingEnabled:YES];
This commit is contained in:
Andreas Linde 2011-12-07 15:46:43 +01:00
parent 9de1e646cc
commit 6c0f91937a
2 changed files with 62 additions and 34 deletions

View File

@ -29,6 +29,8 @@
#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>
#define BWQuincyLog(fmt, ...) do { if([BWQuincyManager sharedQuincyManager].isLoggingEnabled) { NSLog((@"[QuincyLib] %s/%d " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__); }} while(0)
#define kQuincyBundleName @"Quincy.bundle" #define kQuincyBundleName @"Quincy.bundle"
NSBundle *quincyBundle(void); NSBundle *quincyBundle(void);
@ -144,6 +146,7 @@ typedef enum CrashReportStatus {
id <BWQuincyManagerDelegate> _delegate; id <BWQuincyManagerDelegate> _delegate;
BOOL _loggingEnabled;
BOOL _showAlwaysButton; BOOL _showAlwaysButton;
BOOL _feedbackActivated; BOOL _feedbackActivated;
BOOL _autoSubmitCrashReport; BOOL _autoSubmitCrashReport;
@ -189,6 +192,10 @@ typedef enum CrashReportStatus {
/////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////
// settings // settings
// if YES, states will be logged using NSLog. Only enable this for debugging!
// if NO, nothing will be logged. (default)
@property (nonatomic, assign, getter=isLoggingEnabled) BOOL loggingEnabled;
// nil, using the default localization files (Default) // nil, using the default localization files (Default)
// set to another string which will be appended to the Quincy localization file name, "Alternate" is another provided text set // set to another string which will be appended to the Quincy localization file name, "Alternate" is another provided text set
@property (nonatomic, retain) NSString *languageStyle; @property (nonatomic, retain) NSString *languageStyle;

View File

@ -87,6 +87,7 @@ NSString *BWQuincyLocalize(NSString *stringToken) {
@synthesize autoSubmitDeviceUDID = _autoSubmitDeviceUDID; @synthesize autoSubmitDeviceUDID = _autoSubmitDeviceUDID;
@synthesize languageStyle = _languageStyle; @synthesize languageStyle = _languageStyle;
@synthesize didCrashInLastSession = _didCrashInLastSession; @synthesize didCrashInLastSession = _didCrashInLastSession;
@synthesize loggingEnabled = _loggingEnabled;
@synthesize appIdentifier = _appIdentifier; @synthesize appIdentifier = _appIdentifier;
@ -127,6 +128,7 @@ NSString *BWQuincyLocalize(NSString *stringToken) {
_sendingInProgress = NO; _sendingInProgress = NO;
_languageStyle = nil; _languageStyle = nil;
_didCrashInLastSession = NO; _didCrashInLastSession = NO;
_loggingEnabled = NO;
self.delegate = nil; self.delegate = nil;
self.feedbackActivated = NO; self.feedbackActivated = NO;
@ -175,13 +177,13 @@ NSString *BWQuincyLocalize(NSString *stringToken) {
// Enable the Crash Reporter // Enable the Crash Reporter
if (![crashReporter enableCrashReporterAndReturnError: &error]) if (![crashReporter enableCrashReporterAndReturnError: &error])
NSLog(@"Warning: Could not enable crash reporter: %@", error); NSLog(@"WARNING: Could not enable crash reporter: %@", error);
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(startManager) name:BWQuincyNetworkBecomeReachable object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(startManager) name:BWQuincyNetworkBecomeReachable object:nil];
} }
if (!quincyBundle()) { if (!quincyBundle()) {
NSLog(@"WARNING: Quincy.bundle is missing in the app bundle!"); NSLog(@"WARNING: Quincy.bundle is missing, will send reports automatically!");
} }
} }
return self; return self;
@ -256,7 +258,7 @@ NSString *BWQuincyLocalize(NSString *stringToken) {
if (!_sendingInProgress && [self hasPendingCrashReport]) { if (!_sendingInProgress && [self hasPendingCrashReport]) {
_sendingInProgress = YES; _sendingInProgress = YES;
if (!quincyBundle()) { if (!quincyBundle()) {
NSLog(@"Quincy.bundle is missing, sending report automatically!"); NSLog(@"WARNING: Quincy.bundle is missing, sending reports automatically!");
[self _sendCrashReports]; [self _sendCrashReports];
} else if (!self.autoSubmitCrashReport && [self hasNonApprovedCrashReports]) { } else if (!self.autoSubmitCrashReport && [self hasNonApprovedCrashReports]) {
@ -318,6 +320,7 @@ NSString *BWQuincyLocalize(NSString *stringToken) {
} }
if ([_crashFiles count] > 0) { if ([_crashFiles count] > 0) {
BWQuincyLog(@"Pending crash reports found.");
return YES; return YES;
} else } else
return NO; return NO;
@ -531,6 +534,7 @@ NSString *BWQuincyLocalize(NSString *stringToken) {
[[NSUserDefaults standardUserDefaults] synchronize]; [[NSUserDefaults standardUserDefaults] synchronize];
if (crashes != nil) { if (crashes != nil) {
BWQuincyLog(@"Sending crash reports:\n%@", crashes);
[self _postXML:[NSString stringWithFormat:@"<crashes>%@</crashes>", crashes] [self _postXML:[NSString stringWithFormat:@"<crashes>%@</crashes>", crashes]
toURL:[NSURL URLWithString:self.submissionURL]]; toURL:[NSURL URLWithString:self.submissionURL]];
@ -583,6 +587,8 @@ NSString *BWQuincyLocalize(NSString *stringToken) {
} }
_urlConnection = [[NSURLConnection alloc] initWithRequest:request delegate:self]; _urlConnection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
BWQuincyLog(@"Requesting feedback status.");
} }
- (void)_postXML:(NSString*)xml toURL:(NSURL*)url { - (void)_postXML:(NSString*)xml toURL:(NSURL*)url {
@ -633,7 +639,10 @@ NSString *BWQuincyLocalize(NSString *stringToken) {
_urlConnection = [[NSURLConnection alloc] initWithRequest:request delegate:self]; _urlConnection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
if (!_urlConnection) { if (!_urlConnection) {
BWQuincyLog(@"Sending crash reports could not start!");
_sendingInProgress = NO; _sendingInProgress = NO;
} else {
BWQuincyLog(@"Sending crash reports started.");
} }
} }
@ -658,11 +667,13 @@ NSString *BWQuincyLocalize(NSString *stringToken) {
[self.delegate connectionClosed]; [self.delegate connectionClosed];
} }
BWQuincyLog(@"ERROR: %@", [error localizedDescription]);
_sendingInProgress = NO; _sendingInProgress = NO;
} }
- (void)connectionDidFinishLoading:(NSURLConnection *)connection { - (void)connectionDidFinishLoading:(NSURLConnection *)connection {
if (_statusCode >= 200 && _statusCode < 400) { if (_statusCode >= 200 && _statusCode < 400 && _responseData != nil && [_responseData length] > 0) {
[self _cleanCrashReports]; [self _cleanCrashReports];
_feedbackRequestID = nil; _feedbackRequestID = nil;
@ -672,6 +683,8 @@ NSString *BWQuincyLocalize(NSString *stringToken) {
mutabilityOption:NSPropertyListMutableContainersAndLeaves mutabilityOption:NSPropertyListMutableContainersAndLeaves
format:nil format:nil
errorDescription:NULL]; errorDescription:NULL];
BWQuincyLog(@"Received API response: %@", response);
_serverResult = (CrashReportStatus)[[response objectForKey:@"status"] intValue]; _serverResult = (CrashReportStatus)[[response objectForKey:@"status"] intValue];
if ([response objectForKey:@"id"]) { if ([response objectForKey:@"id"]) {
_feedbackRequestID = [[NSString alloc] initWithString:[response objectForKey:@"id"]]; _feedbackRequestID = [[NSString alloc] initWithString:[response objectForKey:@"id"]];
@ -680,6 +693,8 @@ NSString *BWQuincyLocalize(NSString *stringToken) {
_feedbackDelayInterval *= 0.01; _feedbackDelayInterval *= 0.01;
} }
} else { } else {
BWQuincyLog(@"Received API response: %@", [[[NSString alloc] initWithBytes:[_responseData bytes] length:[_responseData length] encoding: NSUTF8StringEncoding] autorelease]);
NSXMLParser *parser = [[NSXMLParser alloc] initWithData:_responseData]; NSXMLParser *parser = [[NSXMLParser alloc] initWithData:_responseData];
// Set self as the delegate of the parser so that it will receive the parser delegate methods callbacks. // Set self as the delegate of the parser so that it will receive the parser delegate methods callbacks.
[parser setDelegate:self]; [parser setDelegate:self];
@ -705,6 +720,12 @@ NSString *BWQuincyLocalize(NSString *stringToken) {
[self showCrashStatusMessage]; [self showCrashStatusMessage];
} }
} }
} else {
if (_responseData == nil || [_responseData length] == 0) {
BWQuincyLog(@"ERROR: Sending failed with an empty response!");
} else {
BWQuincyLog(@"ERROR: Sending failed with status code: %i", _statusCode);
}
} }
[_responseData release]; [_responseData release];