How to disable NSLog all over the app? How to disable NSLog all over the app? xcode xcode

How to disable NSLog all over the app?


Xcode has a precompiled header file ({project-name}-Prefix.pch in the Supporting Files group by default) that is a great place to put code that will be used across every file in the project. For going a step further and improving the log message itself, see Is it true that one should not use NSLog() on production code?.


Add the following lines to your constants file:

#define DEBUGGING NO    //or YES#define NSLog if(DEBUGGING)NSLog

The two following sentences give the same results

#define NSLog

and

#define NSLog //

because all text that begin with // are deleted in a precompiling phase ("//" included)


What I do is put this in the precompiled header file (YourAppName.pch):

#define MyLog if(0); else NSLog

Then I change all NSLog to MyLog everywhere else in the app. It works as if it were NSLog. But when you want to disable NSLog, go back to the .pch file and change the 0 to 1 and presto, all logging stops.