Skip to content

Instantly share code, notes, and snippets.

@dedmons
Created December 29, 2012 03:16
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 dedmons/4404328 to your computer and use it in GitHub Desktop.
Save dedmons/4404328 to your computer and use it in GitHub Desktop.
Improved Logging macros for Objective-C Development. These are modified versions of the solutions here: http://stackoverflow.com/questions/969130/how-to-print-out-the-method-name-and-line-number-and-conditionally-disable-nslog To disable DLog and ULog just a property or method to a class named dontLog
#ifdef DEBUG
# define DLog(fmt, ...) if(![self respondsToSelector:@selector(dontLog)]) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);
#else
# define DLog(...)
#endif
#ifdef DEBUG
# define ULog(fmt, ...) if(![self respondsToSelector:@selector(dontLog)]) { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:[NSString stringWithFormat:@"%s\n [Line %d] ", __PRETTY_FUNCTION__, __LINE__] message:[NSString stringWithFormat:fmt, ##__VA_ARGS__] delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil]; [alert show]; }
#else
# define ULog(...)
#endif
// ALog always displays output regardless of the DEBUG setting
#define ALog(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment