DDLog-printing information of different colors and ddlog-color printing

Source: Internet
Author: User

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.

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.