Skip to content

Instantly share code, notes, and snippets.

@sendoa
Created November 20, 2012 10:05
Show Gist options
  • Save sendoa/4117082 to your computer and use it in GitHub Desktop.
Save sendoa/4117082 to your computer and use it in GitHub Desktop.
Alternatives to NSLog

Using the above code you can now call some new functions within your app, these being:

ALog() will display the standard NSLog but containing function and line number. DLog() will output like NSLog only when the DEBUG variable is set ULog() will show the UIAlertView only when the DEBUG variable is set Each one of these will also include the line number and function that created it, for example, ALog(@"Hello world"); would display as -[LibraryController awakeFromNib] [Line 364] Hello world.

http://overbythere.co.uk/blog/2012/01/alternatives-nslog

#ifdef DEBUG
# define DLog(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);
#else
# define DLog(...)
#endif
#define ALog(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);
#ifdef DEBUG
# define ULog(fmt, ...) { 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment