Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Suppressing NSLog statements for release? [duplicate]

Possible Duplicate:
Do I need to disable NSLog before release Application?

I wonder if someone could help me setup a number of NSLog statements so they print to console when executing in "Debug Mode" but don't print in "Release Mode". I understand I need to add something like DEBUG = 1 to the debug config in Xcode but I can't find where. Also how do I utilise this in my code?

NSLog(@"Print Always");
if(DEBUG) NSLog(@"Print only in debug");

Is there a simple way of doing this?

EDIT_001: I tried following this but the keys now seem to be only listed under "All Settings", and are presenting as nice names. The one I should be using is GCC_PREPROCESSOR_DEFINITIONS, so I needed to find "Preprocessor Macros", select edit and add DEBUG=1 alt text

When you come to use this its simply a case of adding (see below) or some marco to remove the messy #ifdef / #endif tags.

NSLog(@"You always see me?");
#ifdef DEBUG
NSLog(@"Only in DEBUG");
#endif
like image 233
fuzzygoat Avatar asked Feb 28 '23 05:02

fuzzygoat


2 Answers

This is a popular solution:

http://iphoneincubator.com/blog/debugging/the-evolution-of-a-replacement-for-nslog

See comments about using either -DDEBUG=1 or DEBUG=1.

like image 149
Felixyz Avatar answered Mar 02 '23 00:03

Felixyz


The best solution is not to use NSLog in the first place but instead rely on the debugger.

You can set breakpoints that execute debugger commands to print out anything and you can set the breakpoints to execute the debugger commands but not to stop execution. In practice this works just like NSLog.

By using the debugger to do the logging, you don't have to worry about removing the log statements.

like image 29
TechZen Avatar answered Mar 01 '23 23:03

TechZen