1. Installing plugins
Xcodecolors
Github Link: https://github.com/robbiehanson/XcodeColors
Open the Xcodecolors project and compile. It will install Plug and xcodecolors.xcplugin in your computer. Specific path in: ~/library/application Support/developer/shared/xcode/plug-ins/xcodecolors.xcplugin (can take a look).
2. Introduction of third-party libraries
Cocoalumberjack
Github Link: https://github.com/CocoaLumberjack/CocoaLumberjack
3. Modify your printing information to change the NSLog to Ddlog printing, the best new project to use
(ii) Some introductions of Ddlog
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.
Ddlog the output level by default provides several of the following:
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
The log levels provided are:
Log_level_error: Only error logs are displayed.
Log_level_warn: including: Log_level_error
Log_level_info: including: Log_level_warn
Log_level_debug: including: Log_level_info
Log_level_verbose: including: Log_level_debug
Log_level_off: Close Log
(iii) partial use of Ddlog
#import "CocoaLumberjack.h"
static const int Ddloglevel = ddloglevelverbose;//defines the log level [Ddlog Addlogger:[ddttylogger sharedinstance]];// Initialize the Ddlog log output, where we only want the Xcode console output [[Ddttylogger sharedinstance] setcolorsenabled:yes];//enable color discrimination Ddlogerror (@ "error message"); Red Ddlogwarn (@ "Warning%@", @ "ASD"),//Orange Ddloginfo (@ "prompt message:%@", @ "quack");//default is black ddlogverbose (@ "Details error:% D ", 1016); Default is Black
Printing effect:
Tips: If the print color does not change
- Open Product--Edit Scheme
- Select Run-> "Arguments" tab
- Add a new environment Variable named "Xcodecolors" with a value of Yes
- OK, now is the time to witness the miracle, run it once, and you can see.
ddlog-printing information in different colors