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".