ProAnswers.org

Tips and tricks to using NSLog?

I’d like to know if there are any tips and tricks to using NSLog which you guys have picked up.

Here are some useful macros around NSLog I use a lot:

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



 



The DLog macro is used to only output when the DEBUG variable is set (-DDEBUG in the projects's C flags for the debug confirguration).



ALog will always output text (like the regular NSLog).



The output (e.g. ALog(@"Hello world") ) will look like this:

-[LibraryController awakeFromNib] [Line 364] Hello world