Blog

Log to Debug efficiently in Objective-C

Everyone wants to have an effecient logging method that releave him from the stepping debugging.

The following is a macro for debugging showing only in debug mode.

It shows:

  • Current File.
  • Current Function.
  • Current Line.
  • Custom Argments.

#ifdef DEBUG
#   define DLog(fmt, ...) NSLog((@"%s %s [Line %d] " fmt), __FILE__, __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);
#else
#   define DLog(...) ;
#endif

// ALog always displays output regardless of the DEBUG setting
#define ALog(fmt, ...) NSLog((@"%s %s [Line %d] " fmt), __FILE__, __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);

 

Ex: ALog(@"Hello world") will print:

path/to/LibraryController.m  -[LibraryController awakeFromNib] [Line 364] Hello world

 

Enjoy

Reference: http://stackoverflow.com/questions/969130/nslog-tips-and-tricks

  • 0 Comments

Leave a Comment...