Either way, you must make a macro definition in the PCH file
Debug and release to separate, release when log print to cancel
Method One: Simple and straightforward, with a few lines of code, concise but less functional
#ifdef DEBUG #define NSLog (...) NSLog (__va_args__)#define Debugmethod () NSLog (@ "%s", __func__)#else#define NSLog (...) #define Debugmethod ()#endif
Where does this debug set up,
There is a "debug=1" in "Target > Build Settings > Preprocessor Macros > Debug".
When set to debug mode, the Product-->scheme-->schemeedit Scheme settings build is configured to debug, you can print NSLog. Set release, which will not print when the app version is published, improves performance or
#ifdef DEBUG #define **log (S, ...) NSLog (@ "<%p%@:(%d) >%@", Self, [[NSString stringwithutf8string:__file__] lastpathcomponent], __line__, [ NSString stringWithFormat: (s), # #__VA_ARGS__])//Is the method address, the file name, the first line of the file, the custom output #else#define **log (s , ... ) #endif
Which: **log (S, ...) The * * is the name of your own custom, convenient code directly copied away using.
method Two: Third party, colorful log, multi-function, but slightly complex
1. Download the framework
Allows the console to output color plugins
Https://github.com/robbiehanson/XcodeColors
With color log frame
Https://github.com/CocoaLumberjack/CocoaLumberjack
2. Install xcodecolors (output color plug-in)
3. Import the color log frame
===========================================================
1. Defining log Levels
#ifdef DEBUG
static const int ddloglevel = Log_level_verbose;
#else
static const int ddloglevel = Log_level_off;
#endif
2. Initializing a colored log in the Didfinishlaunchingwithoptions method
[Ddlog Addlogger:[ddttylogger sharedinstance];
3. Turn on the color log
[[Ddttylogger sharedinstance] setcolorsenabled:yes];
4. Using a color log
5. Fix Xcode6 does not display color log issue
>in Xcode Bring up the scheme Editor (Product---Edit scheme ...)
>select "Run", and then the "Arguments" tab
>add a new environment Variable named "Xcodecolors" with a value of "YES"
===========================================================
1. Log type
Ddlog: Basic class, which must be introduced.
Ddasllogger: Supports writing debug statements to Apple's logs. It is generally being developed for Mac. Optional.
Ddttylogger: Supports writing debug statements to the Xcode console. Even if we want to use it. Optional.
Ddfilelogger: Supports writing debug statements to the file system. Optional.
2.DDLog log type.
Ddlogerror: Defining output error text
Ddlogwarn: Define output warning text
Ddloginfo: Defining output Message Text
Ddlogdebug: Defining Output Debug Text
Ddlogverbose: Defining output verbose text
3. Log level
>log_level_error, then you will only see the Ddlogerror statement.
>log_level_warn, then you will only see DDLOGERROR and Ddlogwarn statements.
>log_level_info, then you will see the error, warn, and INFO statements.
>log_level_verbose, then you will see all the ddlog statements.
>log_level_off, you will not see any ddlog statements.
===========================================================
1. Custom Colors
[[Ddttylogger sharedinstance] Setforegroundcolor:[uicolor Greencolor] Backgroundcolor:[uicolor PurpleColor] ForFlag :D Dlogflaginfo];
Quick Location Printing method
#define Ddinfolog Ddlogwarn (@ "%d%s", __line__, __func__)
Summary of several popular practices about NSLog in iOS development