Objective:
1) output log is a large loss of system performance
2) The information that is output is easily intercepted, causing the information to be unsafe.
So we're going to cancel all of the logs in the release version (release). It is obviously not a clear choice if you are going to comment out the log one line at a line.
So we can use macros to customize the log output.
One of the simplest examples:
#ifdef debug# define Gclog (FMT, ...) NSLog (FMT), # #__VA_ARGS__); #else # define Gclog (...); #endif
How to use:
Gclog (@ "sdf");
Using macros to customize the output, you can also easily manage the content of the output:
#ifdef DEBUG # define DLOG (FMT, ...) NSLog (@ "[filename:%s]\n""[function name:%s]\n""[line number:% D] \ n"FMT" , __file__, __function__, __line__, # #__VA_ARGS__) ; #else # define DLOG (...); #endif
Excerpt from: http://blog.csdn.net/remote_roamer/article/details/7107320
1) __VA_ARGS__ is a variable-parameter macro that few people know about this macro, which is the new C99 specification, and currently appears to be supported only by GCC (VC6.0 compiler does not support it). The macro front Plus # #的作用在于, when the number of variable parameters is 0 o'clock, here the # #起到把前面多余的"," Remove the effect, otherwise it will compile error, you can try. 2) __FILE__ macro will be replaced with the current source file name at the time of precompilation 3) __LINE__ macro will be replaced with the current line number 4 at precompilation __FUNCTION__ macros will be replaced with the current function name at the time of precompilation. With these macros, especially with __va_args__, the output of debug information becomes much more flexible.
Excerpt from: http://blog.chinaunix.net/uid-22878837-id-2110544.html
iOS custom output with macros (NSLOG)