Suppress NSLog applications for release?

Possible duplicate:
Do I need to disable NSLog before releasing the application?

I wonder if anyone can help me set up several NSLog statements so that they print to the console when executed in "debug mode" but not print in "release mode". I understand that I need to add something like DEBUG = 1 to the debug configuration in Xcode, but I cannot find where. Also how can I use this in my code?

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

Is there an easy way to do this?

EDIT_001: I tried using this , but now the keys are now displayed only in the "All Settings" section and are beautiful names. I have to use GCC_PREPROCESSOR_DEFINITIONS, so I needed to find "Preprocessor Macros", select the edit and add DEBUG=1 alt text

When you start using it, it's just a case of adding (see below) or some kind of brand to remove the messy # ifdef / # endif tags.

 NSLog(@"You always see me?"); #ifdef DEBUG NSLog(@"Only in DEBUG"); #endif 
+4
source share
4 answers

This is a popular solution:

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

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

+3
source

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 anything, and you can set breakpoints for executing debugger commands, but not stop execution. In practice, this works the same as NSLog.

Using a debugger for logging, you don't have to worry about deleting log statements.

+3
source

Please see the answers. How to print the method name and line number and conditionally disable NSLog? . There are some nice macros that can be very useful.

+1
source

I use this:

 -(void)debugWinLog 

{

 NSUserDefaults * defaultsDebug = [NSUserDefaults standardUserDefaults]; theDebugWin = [defaultsDebug boolForKey:@"logger"]; 

}

which is called in awakeFromNib. It checks application plist file for 1 or 0 to write BOOL "logger"

The normal state is if it is off, but during debugging you can turn it on or off as desired in the terminal. with a regular default entry. NSlog statuses are as follows:

 if ( theDebugWin) {NSLog (@"%@", windowState );} 
+1
source

Source: https://habr.com/ru/post/1306711/


All Articles