IOS prints Debug logs.
The following macros are briefly introduced:
1) _ VA_ARGS _ is a macro of a variable parameter. The macro of this variable parameter is added in the new C99 specification, currently, only gcc is supported (not supported by the VC6.0 compiler ). # Is added before the Macro. When the number of variable parameters is 0, # is used to remove ",". Otherwise, compilation errors may occur.
2) _ FILE _ Macro will be replaced with the current source FILE name during pre-compilation.
3) _ LINE _ Macro will be replaced with the current row number during pre-compilation.
4) _ FUNCTION _ macro is replaced with the current FUNCTION name during pre-compilation.
1. Redefine the NSLog of the system. __optimize _ is the macro that will be added by default to release.
[Plain]View plaincopy
- # Ifndef _ OPTIMIZE __
- # Define NSLog (...) NSLog (_ VA_ARGS __)
- # Else
- # Define NSLog (...){}
- # Endif
2. Write # define directly. When the release version is released, comment out # define.
# Define IOS_DEBUG
[Plain]View plaincopy
- # Ifdef IOS_DEBUG
- # Define NSLog (...) NSLog (_ VA_ARGS __)
- # Endif
3.
[Plain]View plaincopy
- # Ifdef DEBUG
- # Define DLog (format ,...) NSLog (@ "[FILE Name: % s]" "[function name: % s]" "[line number: % d]" format), _ FILE __, _ FUNCTION __, _ LINE __, ##__ VA_ARGS __);
- # Else
- # Define DLog (...);
- # Endif
In this way, you need to modify the configuration of the project so that the DLog macro can be compiled during debug compilation to generate detailed log information. In release mode, no console output is generated.
In comparison, the first one is more convenient.