5

In my memory, there's some code that can let the NSLog not work when released.

I don't want to remove my NSLog in my code.It helps a lot on debug mode.

So I want to find a way that can leave them in my code, and also don't slow down the application when released.

Thanks for your help~~

Steven Jiang
  • 1,006
  • 9
  • 21
  • check the top answer here: http://stackoverflow.com/questions/969130/nslog-tips-and-tricks – vakio Jul 24 '12 at 08:43

2 Answers2

5

A common way to remove all NSLog(…) call in a release is to create a macro that is between conditional preprocessor macro and compiles to nothing, something like this:

#ifdef RELEASE
# define NSLog(...) //remove loggin in production
#endif

Put this code in a .h file that is included in every other file, like a Defines.h that is #include'd in the prefix header (.pch).

RELEASE should be a preprocessor macro defined against the Release configuration in the "Build Settings" tab of your target.

Apple LLVM compiler 4.0 - Preprocessing

Related Questions

Community
  • 1
  • 1
Richard Stelling
  • 25,607
  • 27
  • 108
  • 188
1

You will need to replace NSLog with a custom macro.

Put for instance

#ifdef DEBUG
#    define DLog(...) NSLog(__VA_ARGS__)
#else
#    define DLog(...) /* */
#endif
#define ALog(...) NSLog(__VA_ARGS__)

in your prefix pch file.

Use ALog for cases where you always want log output regardless of the state of the debug flag, and DLog for log only in debug mode.

Source

Olotiar
  • 3,225
  • 1
  • 18
  • 37