Skip to content

Instantly share code, notes, and snippets.

@chrislavender
Created October 27, 2013 05:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrislavender/7178163 to your computer and use it in GitHub Desktop.
Save chrislavender/7178163 to your computer and use it in GitHub Desktop.
Macros for logging in an Objective C development environment.
#ifdef DEBUG
// Bog standard Logging
#define DNSLog(fmt, ...) NSLog(fmt, ##__VA_ARGS__);
// Log statement with a bit more detail as to where you are
#define DNSLog1(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);
// Log statement without the normal NSLog fluff at the start
#define DNSLog2(fmt, ...) fprintf( stderr, "%s\n", [[NSString stringWithFormat:(@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__] UTF8String] );
// Logs out to a UILocalNotification, where you can pull it down in Notification Center
#define DNSLogN(fmt, ...) UILocalNotification *localNotif__LINE__ = [[UILocalNotification alloc] init];\
if (localNotif__LINE__) {\
localNotif__LINE__.alertBody = [NSString stringWithFormat:(fmt), ##__VA_ARGS__];\
[[UIApplication sharedApplication] presentLocalNotificationNow:localNotif__LINE__];\
}
// You can use this type to delay expensive logging computation by wrapping it in a block.
typedef NSString *(^LoggingOnlyComposeString)();
#else
// No definition unless debugging is on
#define DNSLog(fmt, ...)
#define DNSLog1(fmt, ...)
#define DNSLog2(fmt, ...)
#define DNSLogN(fmt, ...)
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment