Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

walty

macrumors member
Original poster
Jul 15, 2008
33
0
Hi,

I have finished implementation of an iPhone app, and now is trying to finetune the performance. Throughout my code, I have put a LOT of NSLog statements for debug.

I wonder is there any way for me to DISABLE those NSLog statements (say, by setting a compilation flag) for distribution. I know the NSLog statements will eventually be ignored when run on device, but I don't even want the arguments on NSLog statements to be evaluated.

I know I may comment all the statements, but most of NSLog are useful for future debugging. I don't want to remove & restore them again and again.

Any advice will be greatly appreciated.

Thanks.

have a nice day
walty
 

Sbrocket

macrumors 65816
Jun 3, 2007
1,250
0
/dev/null
No, there is no convenient preprocessor flag as with NSAssert() macros. What I did is make a debugLog() macro that is defined as NSLog() when a certain preprocessor macro is defined (DEBUG, in my case) and nothing elsewise. It looks like this:

Code:
#ifdef DEBUG
	#define debugLog(...) NSLog(__VA_ARGS__)
#else
	#define debugLog(...)		// Nothing
#endif

Then you can just do a simple find & replace to switch all your NSLog() statements with debugLog().

Oh, and the NSLog() messages aren't ignored on the device - the messages will still get logged to the device's system logs, even if you distribute the app, so you'll probably want to do something like this to make sure that your logging statements don't get compiled into release or distribution builds.
 

walty

macrumors member
Original poster
Jul 15, 2008
33
0
Thanks, it works great :)

No, there is no convenient preprocessor flag as with NSAssert() macros. What I did is make a debugLog() macro that is defined as NSLog() when a certain preprocessor macro is defined (DEBUG, in my case) and nothing elsewise. It looks like this:

Code:
#ifdef DEBUG
	#define debugLog(...) NSLog(__VA_ARGS__)
#else
	#define debugLog(...)		// Nothing
#endif

Then you can just do a simple find & replace to switch all your NSLog() statements with debugLog().

Oh, and the NSLog() messages aren't ignored on the device - the messages will still get logged to the device's system logs, even if you distribute the app, so you'll probably want to do something like this to make sure that your logging statements don't get compiled into release or distribution builds.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.