Debuggify is a collection of shortcut macros for quickly adding debugging output to Objective-C methods. See below for examples.
Just add the debuggify.h
header to your project (for example #import
"debuggify.h" in your project's .pch) and set the DEBUG
flag.
Here's a couple of simple examples to give an idea of how debuggify works:
Just add the @debuggify() macro at the beginning of the method you want to debug and pass it any interesting objects you want to log. Optionally add @debuggify_time at the end to print the time it took to execute the method.
@interface SomeClass
@property NSString *someState;
@end
@implementation SomeClass
- (id)init
{
self = [super init];
if (self) {
self.someState = @"I'm doing something..."
}
return self;
}
- (void)doSomethingWith:(SomeClass *)someone
{
@debuggify(self, someone)
sleep(10); // d`oh
@debuggify_time
}
- (NSString *)description
{
return self.someState;
}
@end
Now running this code...
SomeClass *sc = [SomeClass new];
sc.someState = @"I'm doing something else!";
[[SomeClass new] doSomethingWith:sc];
...will print the following message:
> -[SomeClass doSomethingWith:]:
> 0: self = I'm doing something...
> 1: someone = I'm doing something else!
> Execution time: 10.001630ms
Debuggify includes some very basic logging functions for replacing the standard NSLog.
MXLogEmergency(...)
MXLogAlert(...)
MXLogCritical(...)
MXLogError(...)
MXLogWarning(...)
MXLogNotice(...)
MXLogInfo(...)
MXLogDebug(...)
The default (compile-time) log level is set to notice for non-debug builds and to the highest level (debug) for debug builds.
Pull requests are very welcome. It would be nice to make this thing more advanced. One particular thing would be to add support for method paramters. There is already a lot of code out there that does this, but I wanted to keep this short and without any compiled code (i.e. just a header to drop in).
Please report any issues to the GitHub issuetracker.
Thank you to Jake Wharton for the inspiration by creating something similiar (but way more advanced) for Java. I would also like to thank Justin Spahr-Summers for creating the awesome libextobjc from which I am using the macros for metaprogramming. Thanks to David Beck for creating TULogging, which is used (with some modifications) for the debuggify logging facilities.