You can use Three20's debugging facilities instead of NSLog()
/ assert()
. This would give you an ability to turn off debugging messages without commenting out all NSLog
's, sort log messages by importance (error
, warning
, info
).
Turn on debugging(打开调试)
These instructions are for Xcode 3:
- Right-click on project, choose "Get Info".
- In the "Build" tab, choose "Configuration => Debug" (you probably want to enable this only for debug builds)
- While in the "Build" tab, search for "Preprocessor Macros" under the "GCC 4.2 - Preprocessing" section.
- Add a declaration that reads
DEBUG
. That way you enable debugging in general. - Add a declaration that reads
TTMAXLOGLEVEL=TTLOGLEVEL_INFO
. By doing this, you set the default debugging output to beTTLOGLEVEL_INFO
, the most descriptive one.
Use debugging
Logging
Use these instead of NSLog()
. Which level gets printed to the console and which doesn't depends on what's set in preprocessor macros asTTMAXLOGLEVEL
(see above).
TTDERROR(text, ...) // Log level 1 TTDWARNING(text, ...) // Log level 3 TTDINFO(text, ...) // Log level 5 TTDPRINT(text, ...)
Example
If I got this in AppDelegate.m of my project HelloWorld:
- (void)applicationDidFinishLaunching:(UIApplication *)application { TTDINFO(@"Hello!"); }
...the console output would look like this:
2010-05-15 01:04:20.107 HelloWorld[65222:207] -[AppDelegate applicationDidFinishLaunching:](22): Hello!
Conditional logging
This is a type of logging facility which only outputs something if a particular condition is met:
TTDCONDITIONLOG(condition, text, ...);
Example
TTDCONDITIONLOG(TTDFLAG_URLREQUEST, @"Request parameters: %@", request.parameters);
Debug-only assertions
Three20 also provides support for assertions which only work in the debug build.
TTDASSERT(condition_which_would_lead_to_application_termination_when_true);
Example
// Not that implementing safeAddSubview: is a good idea - (void)safeAddSubview:(UIView*)view { TTDASSERT(nil != view); if (nil == view) { return; } [self addSubview:view]; }
See also
Links