1

Possible Duplicate:
Is it true that one should not use NSLog() on production code?
Do I need to disable NSLog before release Application?

I need to remove all the NSLOGs which are present in my project during the Release build. I have tried using the below code , but still accessing the build via phone, still NSLOG shows up in the console.

#ifdef DEBUG
#define debug_NSLog(format, ...) NSLog(format, ## __VA_ARGS__)
#else
#define debug_NSLog(format, ...)
#endif
Community
  • 1
  • 1
Nishan29
  • 353
  • 1
  • 4
  • 16
  • 2
    Are you using `debug_NSLog` in your code in place of `NSLog`? – mttrb Oct 09 '12 at 10:59
  • Please assign the Constant value into the .pch file and assign the boolean value and check weather the value is true then display other wise not display. – Nimit Parekh Oct 09 '12 at 11:01
  • May your answer over here http://stackoverflow.com/questions/300673/is-it-true-that-one-should-not-use-nslog-on-production-code – Nimit Parekh Oct 09 '12 at 11:05

3 Answers3

13

To simply remove NSLogs:

#define NSLog(s,...)

A #define without a substitution specified will substitute nothing, deleting anything that matches that #define. This works with simple token defines and with function-like defines like the above.

Craig Ringer
  • 307,061
  • 76
  • 688
  • 778
Stas
  • 9,925
  • 9
  • 42
  • 77
  • I have used this "#define NSLog(s,...)" , but still running the app in the RELEASE MODE within the device, still NSLOG comes in the console. – Nishan29 Oct 09 '12 at 11:49
4

Use the following code

#ifdef DEBUGGING
# define DBLog(fmt,...) NSLog(@"%@",[NSString stringWithFormat:(fmt), ##__VA_ARGS__]);
#else
# define DBLog(...)
#endif 

Make sure the compiler flags are properly set.

Also, when you checked the console, did you check if you were using release mode ?

zahreelay
  • 1,742
  • 12
  • 18
  • This is pretty much functionally equivalent to the OPs `debug_NSLog`. How does this answer the OPs question? – mttrb Oct 09 '12 at 11:04
  • may be he missed setting the compiler flag or build was in debug mode when he checked the console, which I have mentioned . – zahreelay Oct 09 '12 at 11:07
  • This is another way, and i find this easy being in the current state of my app release: #ifndef DEBUG #define NSLog(...) /* suppress NSLog when in release mode */ #endif – Ashwin G Jul 14 '16 at 14:12
1

Use this

#if TARGET_IPHONE_SIMULATOR
#define NSLog(fmt,...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);
#else
#define NSLog(...)
#endif

This will print NSLog if you are running it on simulator..

Mehul Mistri
  • 15,037
  • 14
  • 70
  • 94
  • many devs are testing and debugging on actual devices not sims, but it could be useful for some. – zonabi May 04 '15 at 19:41