Android Development Tips

Source: Internet
Author: User
Tags print format

The use of Logcat tools in Android development

Logcat is a command-line tool in Android that can be used to get the log information for a program, and this appendix explains how to use it and some of its techniques.

1. How to use

Logcat use the following method:

LogCat [Options] [Filterspecs]

The options for Logcat include:

-S sets the filter, such as specifying ' *:s '.

-F <filename> Output to file, default is standard output.

-R [<kbytes>] Rotate log every kbytes. (if unspecified). Requires–f.

-N <count> sets max number of rotated logs to <count>, default 4.

-V <format> Set the print format for log, <format> is one of the following:

Brief process Tag thread raw time threadtime long.

-C clears all logs and exits.

-D gets all logs and exits (without blocking).

-G Gets the size of the ring buffer and exits.

-B <buffer> Request different ring buffers (' main ' (default), ' Radio ', ' Events ').

-B outputs log to binary.

The format of the filter is a string like this:

<tag>[:p Riority]

Where <tag> means log component, tag (or use * for all), the priority is as follows:

V Verbose

D Debug

I Info

W Warn

E Error

F Fatal

S Silent

In fact, Logcat's function is determined by the Android class Android.util.Log, and the method of using log in the program is as follows:

LOG.V ()--------------------VERBOSE

LOG.D ()--------------------DEBUG

LOG.I ()--------------------INFO

LOG.W ()--------------------WARN

LOG.E ()--------------------ERROR

The above log level in turn, the debug information should only exist in the development, info, WARN, error 3 kinds of log will appear in the release version.

For Java classes, you can declare a string constant Tag,logcat can distinguish between different logs based on it, for example, in the calculator (Calculator) class, the definition is as follows:

public class Calculator extends Activity {

/* ...... */

private static final String Log_tag = "Calculator";

Private static Final Boolean DEBUG = false;

Private static Final Boolean log_enabled = DEBUG? Config.LOGD:Config.LOGV;

/* ...... */

As a result, all logs used in Calculator begin with "Calculator".

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.