#define NSLog (...) still print output to the console
I tried to disable NSLog in release build.
I put the following code in .pch file
开发者_C百科#ifndef __OPTIMIZE__
# define NSLog(...) NSLog(__VA_ARGS__) #else # define NSLog(...) {} #endif
It's not working, so I tried
# define NSLog(...) {}
It still prints output to the console.
Any help will be good, thanks!
you would declare your own log function and use that instead. its implementation could go through NSLogv, if you want a va list. its implementation would also not forward the messages to NSLogv when disabled, so you will likely need more than one flavor of logger.
Sounds like what you want is similar to this definition for DLog from this previous SO answer on NSLog tips and tricks.
#ifdef DEBUG
# define DLog(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);
#else
# define DLog(...)
#endif
Make sure __OPTIMIZE__
is defined in the build settings or higher up in the .pch file itself and that the pch file is set in the Prefix Header (GCC_PREFIX_HEADER) Build Settings. Also you can define NSLog(...) as nothing
#define NSLog(...)
Preprocessor macro set in Build Setting of project having: DEBUG=1 $(inherited)
So now just use : if(DEBUG) NSLog(@"Your log");
In you application .pch file put following line. define NSLog(dese,...)
It will stop printing.
精彩评论