Created
October 27, 2013 05:05
-
-
Save chrislavender/7178163 to your computer and use it in GitHub Desktop.
Macros for logging in an Objective C development environment.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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