DDLog-printing information of different colors and ddlog-color printing
(1) download and install
1. Install the plug-in
XcodeColors
Github link: https://github.com/robbiehanson/XcodeColors
Open the XcodeColors project and compile it. It will install XcodeColors. xcplugin on your computer. The specific path is :~ /Library/Application Support/Developer/Shared/Xcode/Plug-ins/XcodeColors. xcplugin (you can take a look ).
2. Introduce a third-party library
CocoaLumberjack
Github link: https://github.com/CocoaLumberjack/CocoaLumberjack
3. Modify your printing information and replace NSLog with DDLog for printing. It is best to use it for new projects.
(2) Introduction to DDLog
DDLog: basic class, which must be introduced.
DDASLLogger: supports writing debugging statements to Apple logs. Generally, it is being developed for Mac. Optional.
DDTTYLogger: supports writing debugging statements to the xCode console. Even if we use it. Optional.
DDFileLogger: supports writing debugging statements to the file system. Optional.
DDLogBy default, the following output levels are available:
DDLogError: Define output error text
DDLogWarn: defines the output warning text
DDLogInfo: defines the output text.
DDLogDebug: Define output debugging text
DDLogVerbose: defines the output detailed text
The log level is:
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: Disable logs.
(3) Use the DDLog
# Import "CocoaLumberjack. h"
Static const int ddLogLevel = DDLogLevelVerbose; // defines the log level [DDLog addLogger: [DDTTYLogger sharedInstance]; // initializes the output of DDLog logs. Here, we only want to output [[DDTTYLogger sharedInstance] setColorsEnabled: YES] On the xCode console; // enable color differentiation DDLogError (@ "error message "); // red DDLogWarn (@ "Warning % @", @ "asd"); // orange DDLogInfo (@ "prompt message: % @", @ ""); // The default value is black DDLogVerbose (@ "error: % d", 1016); // The default value is black.
Print effect:
Tips: If the print color does not change
- Open Product-> Edit Scheme
- Choose Run> "Arguments" tab.
- Add a new Environment Variable named "XcodeColors" with the value "YES ".
- OK. Now is the time to witness the miracle. You can see it once you run it.