The use and color changes of log for Android development

Source: Internet
Author: User

In the process of program development, log is a widely used mechanism for documenting program execution, which can be used for both program debugging and event logging in product operations. The Android system provides a simple, convenient log mechanism that developers can easily use. This article briefly describes the use of log in Android and the change in the log color in Android Studio.

To use log, we need to import Android.util.Log first, where log is commonly used in 5 ways:log.v () log.d ( ) log.i () LOG.W ( ) and log.e () . According to the initial letter corresponds to VERBOSE,DEBUG,information,WARNING,ERROR. Among them:

1, log.v debugging color is black , any message will be output.

2, the output color of the LOG.D is blue , only output debug debugging meaning, but he will output the upper level of information.

3, LOG.I output is green , general informational message information, it will not output LOG.V and LOG.D information, but will display I, W and e information.

4, log.w the meaning of Orange , can be seen as a warning warning, we generally need to pay attention to optimize the Android code, while selecting it will also output LOG.E information.

5, LOG.E is red, you can think of error errors, here only the red error message, these errors need our careful analysis, view the stack of information.

We create a new button, and then the Click event is set to:

        LOG.V ("Mainactivity", "This is Verbose.");        LOG.D ("Mainactivity", "This is Debug.");        LOG.I ("Mainactivity", "This is Information");        LOG.W ("Mainactivity", "This is Warning.");        LOG.E ("Mainactivity", "This is Error.");

At this point, when we click the button, the log message is displayed in Android/logcat:

However, we found that the log information may be white and red on your computer. So how to change the color of log information?

    1. File->settings or CTRL + ALT +s
    2. Find Android Logcat, editor-and Colors &fonts, or enter Logcat in the search box above
    3. Click Verbose, Info, debug options, and then use inberited attributes to remove the tick
    4. Then select the check box in front of the Foreground, you can double-click the back to choose the color
    5. Apply–>ok

We can change the log color into the next, we can get the log effect shown.

Log Color value
VERBOSE bbbbbb
DEBUG 0070BB
Infomation 48bb31
WARNING BBBB23
ERROR FF0006
Assert 8f0005

This will give you the above effect.

The complete code is as follows:

Import Android.app.activity;import android.os.bundle;import Android.util.log;import Android.view.view;import    Android.widget.button;public class Mainactivity extends Activity {private button button;        @Override protected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);        Setcontentview (R.layout.activity_main);        Button = (button) Findviewbyid (R.id.button);                Button.setonclicklistener (New View.onclicklistener () {@Override public void OnClick (View v) {                LOG.V ("Mainactivity", "This is Verbose.");                LOG.D ("Mainactivity", "This is Debug.");                LOG.I ("Mainactivity", "This is Information");                LOG.W ("Mainactivity", "This is Warning.");            LOG.E ("Mainactivity", "This is Error.");    }        }); }}

The use and color changes of log for Android development

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.