Basic usage of Android log class

Source: Internet
Author: User

The Log class describes:

API for sending log output. Generally, use the log.v () log.d () log.i () LOG.W () and LOG.E () methods.

The order in terms of verbosity, from least to most are ERROR, WARN, INFO, DEBUG, VERBOSE.

Verbose should never be compiled to an application except during development. Debug logs is compiled in and stripped at runtime.

Error, warning and info logs is always kept.

TIP:

A good convention is to declare a TAG constant with your class: and use that in private static final String TAG = "MyActivity"; subsequent calls to the log methods.

TIP:

Don ' t forget that's when do a call like that if you Log.v(TAG, "index=" + i); ' re building the string to pass into LOG.D, the compiler US Es a StringBuilder and at least three allocations occur:the StringBuilder itself, the buffer, and the String object.

Realistically, there is also another buffer allocation and copy, and even more pressure on the GC. That means this if your log message is filtered out, you might be doing significant work and incurring significant overhea D.

The log class is android.util in the package, and there are some static methods.

The default output is to use the log class.

Several important methods of the Log Class 1. LOG.V ()

V, verbose, Chinese: verbose, output the most common information.

Two overloads:

publicstaticintvpublicstaticintv(String tag, String msg, Throwable tr)

tag is the tag, generally called the name of the class, MSG is the output information, the other output method is similar.

2.LOG.D ()

d, debug, output debug information.

3.LOG.I ()

I, i.e. information, outputs general information.

4.LOG.W ()

W, i.e. warning, warning message.

5.LOG.E ()

E, which is error, outputs a false message.

Basic usage of Android log class

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.