Skip to content
This repository has been archived by the owner on Jan 13, 2022. It is now read-only.

Commit

Permalink
Implement conditional debug logs. Please see TTDebug.h for documentat…
Browse files Browse the repository at this point in the history
…ion.

Added TTDCONDITIONLOG.
  • Loading branch information
jverkoey committed Dec 6, 2009
1 parent ad19e17 commit 3b09e30
Show file tree
Hide file tree
Showing 13 changed files with 95 additions and 36 deletions.
3 changes: 2 additions & 1 deletion CHANGES
@@ -1,11 +1,12 @@

Changes from November 29, 2009

- [NEW] TTDCONDITIONLOG added to TTDebug.h

- [FIXED] Table view delete-row animation slides to left, not up

- [FIXED] Table view show-menu animation slides down, not left


Changes from November 27, 2009

- [NEW] loadSynchronous added to TTURLRequest.
Expand Down
2 changes: 1 addition & 1 deletion src/TTLauncherView.m
Expand Up @@ -493,7 +493,7 @@ - (void)updateTouch {
}

CGFloat springLoadDistance = _dragButton.width*kSpringLoadFraction;
TTDINFO(@"%f < %f", springLoadDistance, _dragButton.center.x);
TTDCONDITIONLOG(TTDFLAG_LAUNCHERVIEW, @"%f < %f", springLoadDistance, _dragButton.center.x);
BOOL goToPreviousPage = _dragButton.center.x - springLoadDistance < 0;
BOOL goToNextPage = ((_scrollView.width - _dragButton.center.x) - springLoadDistance) < 0;
if (goToPreviousPage || goToNextPage) {
Expand Down
6 changes: 3 additions & 3 deletions src/TTNavigator.m
Expand Up @@ -222,7 +222,7 @@ - (UIViewController*)openURL:(NSString*)URL parent:(NSString*)parentURL query:(N
[self beginDelay];
}

TTDINFO(@"OPENING URL %@", URL);
TTDCONDITIONLOG(TTDFLAG_NAVIGATOR, @"OPENING URL %@", URL);

TTURLNavigatorPattern* pattern = nil;
UIViewController* controller = [self viewControllerForURL:URL query:query pattern:&pattern];
Expand Down Expand Up @@ -511,7 +511,7 @@ - (void)cancelDelay {
- (void)persistViewControllers {
NSMutableArray* path = [NSMutableArray array];
[self persistController:_rootViewController path:path];
TTDINFO(@"DEBUG PERSIST %@", path);
TTDCONDITIONLOG(TTDFLAG_NAVIGATOR, @"DEBUG PERSIST %@", path);

// Check if any of the paths were "important", and therefore unable to expire
BOOL important = NO;
Expand Down Expand Up @@ -540,7 +540,7 @@ - (UIViewController*)restoreViewControllers {
NSDate* timestamp = [defaults objectForKey:@"TTNavigatorHistoryTime"];
NSArray* path = [defaults objectForKey:@"TTNavigatorHistory"];
BOOL important = [[defaults objectForKey:@"TTNavigatorHistoryImportant"] boolValue];
TTDINFO(@"DEBUG RESTORE %@ FROM %@", path, [timestamp formatRelativeTime]);
TTDCONDITIONLOG(TTDFLAG_NAVIGATOR, @"DEBUG RESTORE %@ FROM %@", path, [timestamp formatRelativeTime]);

BOOL expired = _persistenceExpirationAge
&& -timestamp.timeIntervalSinceNow > _persistenceExpirationAge;
Expand Down
12 changes: 6 additions & 6 deletions src/TTTableViewController.m
Expand Up @@ -372,12 +372,12 @@ - (void)model:(id<TTModel>)model didUpdateObject:(id)object atIndexPath:(NSIndex
atIndexPath:indexPath];
if (newIndexPath) {
if (newIndexPath.length == 1) {
TTDINFO(@"UPDATING SECTION AT %@", newIndexPath);
TTDCONDITIONLOG(TTDFLAG_TABLEVIEWMODIFICATIONS, @"UPDATING SECTION AT %@", newIndexPath);
NSInteger sectionIndex = [newIndexPath indexAtPosition:0];
[_tableView reloadSections:[NSIndexSet indexSetWithIndex:sectionIndex]
withRowAnimation:UITableViewRowAnimationTop];
} else if (newIndexPath.length == 2) {
TTDINFO(@"UPDATING ROW AT %@", newIndexPath);
TTDCONDITIONLOG(TTDFLAG_TABLEVIEWMODIFICATIONS, @"UPDATING ROW AT %@", newIndexPath);
[_tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath]
withRowAnimation:UITableViewRowAnimationTop];
}
Expand All @@ -400,12 +400,12 @@ - (void)model:(id<TTModel>)model didInsertObject:(id)object atIndexPath:(NSIndex
atIndexPath:indexPath];
if (newIndexPath) {
if (newIndexPath.length == 1) {
TTDINFO(@"INSERTING SECTION AT %@", newIndexPath);
TTDCONDITIONLOG(TTDFLAG_TABLEVIEWMODIFICATIONS, @"INSERTING SECTION AT %@", newIndexPath);
NSInteger sectionIndex = [newIndexPath indexAtPosition:0];
[_tableView insertSections:[NSIndexSet indexSetWithIndex:sectionIndex]
withRowAnimation:UITableViewRowAnimationTop];
} else if (newIndexPath.length == 2) {
TTDINFO(@"INSERTING ROW AT %@", newIndexPath);
TTDCONDITIONLOG(TTDFLAG_TABLEVIEWMODIFICATIONS, @"INSERTING ROW AT %@", newIndexPath);
[_tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath]
withRowAnimation:UITableViewRowAnimationTop];

Expand All @@ -431,12 +431,12 @@ - (void)model:(id<TTModel>)model didDeleteObject:(id)object atIndexPath:(NSIndex
atIndexPath:indexPath];
if (newIndexPath) {
if (newIndexPath.length == 1) {
TTDINFO(@"DELETING SECTION AT %@", newIndexPath);
TTDCONDITIONLOG(TTDFLAG_TABLEVIEWMODIFICATIONS, @"DELETING SECTION AT %@", newIndexPath);
NSInteger sectionIndex = [newIndexPath indexAtPosition:0];
[_tableView deleteSections:[NSIndexSet indexSetWithIndex:sectionIndex]
withRowAnimation:UITableViewRowAnimationLeft];
} else if (newIndexPath.length == 2) {
TTDINFO(@"DELETING ROW AT %@", newIndexPath);
TTDCONDITIONLOG(TTDFLAG_TABLEVIEWMODIFICATIONS, @"DELETING ROW AT %@", newIndexPath);
[_tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath]
withRowAnimation:UITableViewRowAnimationLeft];
}
Expand Down
6 changes: 3 additions & 3 deletions src/TTURLCache.m
Expand Up @@ -69,7 +69,7 @@ - (void)expireImagesFromMemory {
while (_imageSortedList.count) {
NSString* key = [_imageSortedList objectAtIndex:0];
UIImage* image = [_imageCache objectForKey:key];
// TTDINFO(@"EXPIRING %@", key);
TTDCONDITIONLOG(TTDFLAG_URLCACHE, @"EXPIRING %@", key);

_totalPixelCount -= image.size.width * image.size.height;
[_imageCache removeObjectForKey:key];
Expand Down Expand Up @@ -413,11 +413,11 @@ - (void)invalidateAll {

- (void)logMemoryUsage {
#if TTLOGLEVEL_INFO <= TTMAXLOGLEVEL
TTDINFO(@"======= IMAGE CACHE: %d images, %d pixels ========", _imageCache.count, _totalPixelCount);
TTDCONDITIONLOG(TTDFLAG_URLCACHE, @"======= IMAGE CACHE: %d images, %d pixels ========", _imageCache.count, _totalPixelCount);
NSEnumerator* e = [_imageCache keyEnumerator];
for (NSString* key ; key = [e nextObject]; ) {
UIImage* image = [_imageCache objectForKey:key];
TTDINFO(@" %f x %f %@", image.size.width, image.size.height, key);
TTDCONDITIONLOG(TTDFLAG_URLCACHE, @" %f x %f %@", image.size.width, image.size.height, key);
}
#endif
}
Expand Down
4 changes: 2 additions & 2 deletions src/TTURLRequest.m
Expand Up @@ -183,7 +183,7 @@ - (NSData*)generatePostBody {
[_parameters removeObjectForKey:imageKey];
}

//TTDINFO(@"Sending %s", [body bytes]);
TTDCONDITIONLOG(TTDFLAG_URLREQUEST, @"Sending %s", [body bytes]);
return body;
}

Expand Down Expand Up @@ -248,7 +248,7 @@ - (BOOL)send {
[_parameters setObject:@"[FILTERED]" forKey:@"password"];
}

TTDINFO(@"SEND %@ %@", self.URL, self.parameters);
TTDCONDITIONLOG(TTDFLAG_URLREQUEST, @"SEND %@ %@", self.URL, self.parameters);

if (password) {
[_parameters setObject:password forKey:@"password"];
Expand Down
12 changes: 6 additions & 6 deletions src/TTURLRequestQueue.m
Expand Up @@ -85,7 +85,7 @@ - (void)dealloc {
//////////////////////////////////////////////////////////////////////////////////////////////////

- (void)connectToURL:(NSURL*)URL {
TTDINFO(@"Connecting to %@", _URL);
TTDCONDITIONLOG(TTDFLAG_URLREQUEST, @"Connecting to %@", _URL);
TTNetworkRequestStarted();

TTURLRequest* request = _requests.count == 1 ? [_requests objectAtIndex:0] : nil;
Expand Down Expand Up @@ -158,7 +158,7 @@ - (void)connection:(NSURLConnection*)connection didReceiveResponse:(NSHTTPURLRes
NSDictionary* headers = [response allHeaderFields];
int contentLength = [[headers objectForKey:@"Content-Length"] intValue];
if (contentLength > _queue.maxContentLength && _queue.maxContentLength) {
TTDINFO(@"MAX CONTENT LENGTH EXCEEDED (%d) %@", contentLength, _URL);
TTDCONDITIONLOG(TTDFLAG_URLREQUEST, @"MAX CONTENT LENGTH EXCEEDED (%d) %@", contentLength, _URL);
[self cancel];
}

Expand Down Expand Up @@ -187,7 +187,7 @@ - (void)connectionDidFinishLoading:(NSURLConnection *)connection {
[_queue performSelector:@selector(loader:didLoadResponse:data:) withObject:self
withObject:_response withObject:_responseData];
} else {
TTDINFO(@" FAILED LOADING (%d) %@", _response.statusCode, _URL);
TTDCONDITIONLOG(TTDFLAG_URLREQUEST, @" FAILED LOADING (%d) %@", _response.statusCode, _URL);
NSError* error = [NSError errorWithDomain:NSURLErrorDomain code:_response.statusCode
userInfo:nil];
[_queue performSelector:@selector(loader:didFailLoadWithError:) withObject:self
Expand All @@ -199,7 +199,7 @@ - (void)connectionDidFinishLoading:(NSURLConnection *)connection {
}

- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
TTDINFO(@" FAILED LOADING %@ FOR %@", _URL, error);
TTDCONDITIONLOG(TTDFLAG_URLREQUEST, @" FAILED LOADING %@ FOR %@", _URL, error);

TTNetworkRequestStopped();

Expand Down Expand Up @@ -514,7 +514,7 @@ - (void)loader:(TTRequestLoader*)loader didLoadResponse:(NSHTTPURLResponse*)resp
}

- (void)loader:(TTRequestLoader*)loader didFailLoadWithError:(NSError*)error {
TTDINFO(@"ERROR: %@", error);
TTDCONDITIONLOG(TTDFLAG_URLREQUEST, @"ERROR: %@", error);
[self removeLoader:loader];
[loader dispatchError:error];
[self loadNextInQueue];
Expand All @@ -532,7 +532,7 @@ - (void)loaderDidCancel:(TTRequestLoader*)loader wasLoading:(BOOL)wasLoading {
//////////////////////////////////////////////////////////////////////////////////////////////////

- (void)setSuspended:(BOOL)isSuspended {
// TTDINFO(@"SUSPEND LOADING %d", isSuspended);
TTDCONDITIONLOG(TTDFLAG_URLREQUEST, @"SUSPEND LOADING %d", isSuspended);
_suspended = isSuspended;

if (!_suspended) {
Expand Down
4 changes: 2 additions & 2 deletions src/TTViewController.m
Expand Up @@ -98,7 +98,7 @@ - (void)awakeFromNib {
}

- (void)dealloc {
TTDINFO(@"DEALLOC %@", self);
TTDCONDITIONLOG(TTDFLAG_VIEWCONTROLLERS, @"DEALLOC %@", self);

[[TTURLRequestQueue mainQueue] cancelRequestsWithDelegate:self];

Expand Down Expand Up @@ -177,7 +177,7 @@ - (void)viewWillDisappear:(BOOL)animated {
}

- (void)didReceiveMemoryWarning {
TTDINFO(@"MEMORY WARNING FOR %@", self);
TTDCONDITIONLOG(TTDFLAG_VIEWCONTROLLERS, @"MEMORY WARNING FOR %@", self);

if (_hasViewAppeared && !_isViewAppearing) {
NSMutableDictionary* state = [[NSMutableDictionary alloc] init];
Expand Down
4 changes: 4 additions & 0 deletions src/Three20.xcodeproj/project.pbxproj
Expand Up @@ -181,6 +181,7 @@
EBA17A2010B4DDD500835016 /* NSDataAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = EBA17A1E10B4DDD500835016 /* NSDataAdditions.m */; };
EBA17A3810B4DF5E00835016 /* NSDataAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = EBA17A3710B4DF5E00835016 /* NSDataAdditions.h */; };
EBBB349710B36CCE00AD5BCF /* TTDebug.h in Headers */ = {isa = PBXBuildFile; fileRef = EBBB349610B36CCE00AD5BCF /* TTDebug.h */; };
EBDC8EB610C5CCB000257247 /* TTDebugFlags.h in Headers */ = {isa = PBXBuildFile; fileRef = EBDC8EB510C5CCB000257247 /* TTDebugFlags.h */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
Expand Down Expand Up @@ -359,6 +360,7 @@
EBA17A1E10B4DDD500835016 /* NSDataAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NSDataAdditions.m; sourceTree = "<group>"; };
EBA17A3710B4DF5E00835016 /* NSDataAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = NSDataAdditions.h; path = Three20/NSDataAdditions.h; sourceTree = "<group>"; };
EBBB349610B36CCE00AD5BCF /* TTDebug.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = TTDebug.h; path = Three20/TTDebug.h; sourceTree = "<group>"; };
EBDC8EB510C5CCB000257247 /* TTDebugFlags.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = TTDebugFlags.h; path = Three20/TTDebugFlags.h; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -645,6 +647,7 @@
BE7604D80F8DE01400C9F4BB /* TTDefaultStyleSheet.m */,
EBBB349610B36CCE00AD5BCF /* TTDebug.h */,
EB1F6C5D10B36C32003DAA1F /* TTDebug.m */,
EBDC8EB510C5CCB000257247 /* TTDebugFlags.h */,
);
name = Global;
sourceTree = "<group>";
Expand Down Expand Up @@ -795,6 +798,7 @@
EBBB349710B36CCE00AD5BCF /* TTDebug.h in Headers */,
EBA17A3810B4DF5E00835016 /* NSDataAdditions.h in Headers */,
C6620EAD109CEDA400EC35C6 /* UIWindowAdditions.h in Headers */,
EBDC8EB610C5CCB000257247 /* TTDebugFlags.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
49 changes: 40 additions & 9 deletions src/Three20/TTDebug.h
Expand Up @@ -15,27 +15,48 @@
*/

//
// A priority-based, debug-only logging interface.
// A debug-only logging interface with priority and contional logs.
//
// How to use it
// -------------
//
// To output text to the console:
// TTDINFO(@"Logging text with args %@", stringArg);
// or
// The basic idea is that all TTD macros will only exist in debug builds.
// A debug build is defined by a build that has the DEBUG preprocessor macro defined.
//
// There are four features of this debugging interface:
//
// 1) General-purpose logging
// 2) Priority-based logging
// 3) Condition-based logging
// 4) Debug-only assertions
//
// 1) General purpose logging:
//
// TTDPRINT(@"Logging text with args %@", stringArg);
// etc...
//
// 2) Priority-based logging
//
// Logs that will only be displayed if the project logging level is high enough.
//
// TTDWARNING(@"Priority logging text with args %@", stringArg);
//
// Each macro will only display its logging information if its level is below
// TTMAXLOGLEVEL. TTDPRINT is an exception to this in that it will always
// log the text, regardless of log level. See "Default log level" for more info
// about log levels.
//
// Note: these logging macros will only log if the DEBUG macro is set.
// 3) Condition-based logging
//
// TTDCONDITIONLOG(some_condition, @"This will output if some_condition is true");
//
// 4) Debug-only assertions
//
// To assert something in debug mode:
// TTDASSERT(value == 4);
//
// If a debug-only assertions fails in the simulator, gdb will be loaded at the exact assertion
// line.
//
// Default log level
// -----------------
//
Expand All @@ -47,6 +68,7 @@
// ---------------------
//
// You need to set TTMAXLOGLEVEL in your project settings as a preprocessor macro.
// If you don't, TTLOGLEVEL_WARNING is the default.
// - To do so in Xcode, find the target you wish to configure in the
// "Groups and Files" view. Right click it and click "Get Info".
// - Under the "Build" tab, look for the Preprocessor Macros setting.
Expand All @@ -67,17 +89,17 @@
// TTDERROR(text, ...)
// TTDWARNING(text, ...)
// TTDINFO(text, ...)
// TTDCONDITIONLOG(condition, text, ...)
// TTDPRINT(text, ...) - Generic logging function, similar to deprecated TTLOG
//
// Output format example:
// "/path/to/file(line_number): <message>"
//
//
// ^ ^
// | Informational |
// | - - - - - - - | <- The max log level. Only logs with a level
// | Warning | below this line will be output.
// | |
// |- - Warning - -| <- The default max log level. Only logs with a level
// | | below this line will be displayed.
// | Error |
// | |
// -----------------
Expand Down Expand Up @@ -134,3 +156,12 @@
#else
#define TTDINFO(xx, ...) ((void)0)
#endif

#ifdef DEBUG
#define TTDCONDITIONLOG(condition, xx, ...) { if ((condition)) { \
TTDPRINT(xx, ##__VA_ARGS__); \
} \
} ((void)0)
#else
#define TTDCONDITIONLOG(condition, xx, ...) ((void)0)
#endif
22 changes: 22 additions & 0 deletions src/Three20/TTDebugFlags.h
@@ -0,0 +1,22 @@
/**
* Copyright 2009 Facebook
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#define TTDFLAG_VIEWCONTROLLERS 0
#define TTDFLAG_NAVIGATOR 0
#define TTDFLAG_TABLEVIEWMODIFICATIONS 0
#define TTDFLAG_LAUNCHERVIEW 0
#define TTDFLAG_URLREQUEST 0
#define TTDFLAG_URLCACHE 0
3 changes: 2 additions & 1 deletion src/Three20/TTGlobal.h
@@ -1,5 +1,7 @@
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import "Three20/TTDebug.h"
#import "Three20/TTDebugFlags.h"
#import "Three20/NSObjectAdditions.h"
#import "Three20/NSStringAdditions.h"
#import "Three20/NSDateAdditions.h"
Expand All @@ -18,7 +20,6 @@
#import "Three20/UITableViewAdditions.h"
#import "Three20/UIWebViewAdditions.h"
#import "Three20/UIToolbarAdditions.h"
#import "Three20/TTDebug.h"

///////////////////////////////////////////////////////////////////////////////////////////////////
// Logging Helpers
Expand Down
4 changes: 2 additions & 2 deletions src/UIViewControllerAdditions.m
Expand Up @@ -34,11 +34,11 @@ - (void)dealloc {
}

- (void)didAddSubview:(UIView*)subview {
TTDINFO(@"ADD %@", subview);
TTDCONDITIONLOG(TTDFLAG_VIEWCONTROLLERS, @"ADD %@", subview);
}

- (void)willRemoveSubview:(UIView*)subview {
TTDINFO(@"REMOVE %@", subview);
TTDCONDITIONLOG(TTDFLAG_VIEWCONTROLLERS, @"REMOVE %@", subview);
[self removeFromSuperview];
}

Expand Down

0 comments on commit 3b09e30

Please sign in to comment.