This is an excerpt from androidin.com. For friends who are studying Android, they can use tools for reference.
Http://wuhua.iteye.com/category/26760
(The hanchao3c Android Developer Forum is original. For more information, see)
Logcat is a command line tool in Android that can be used to obtain the log information of a program.
Use logcat as follows:
Logcat [Options] [filterspecs]
Logcat options include:
-S sets the filter, for example, specifying '*: s'
-F <FILENAME>: output to the file. The default value is standard output.
-R [<Kbytes>] rotate log every Kbytes. (16 if unspecified). Requires-F
-N <count> Sets max number of rotated logs to <count>, default 4
-V <format> sets the log printing format. <format> is the following:
Brief process tag thread raw time threadtime long
-C: Clear all logs and exit
-D: Get all logs and exit (not blocked)
-G: Obtain the ring buffer size and exit.
-B <buffer> requests different ring buffers ('main' (default), 'Radio ', 'events ')
-B Outputs the log to binary.
The filter format is a string like this:
<Tag> [: priority]
<Tag> indicates the log component, and the tag (or use * to indicate all). The priority is as follows:
V Verbose
D Debug
I Info
W Warn
E Error
F Fatal
S Silent
In fact, the function of logcat is determined by Android. util. Log. The log usage in the program is as follows:
Log. v () ------------------ VERBOSE
Log. d () ------------------ DEBUG
Log. I () ------------------ INFO
Log. w () ------------------ WARN
Log. e () ------------------ ERROR
The above log levels increase sequentially. The DEBUG information should only exist in the development, INFO, WARN, and ERROR logs will appear in the released version.
For JAVA classes, you can declare a String constant TAG, and Logcat can distinguish different logs based on it. For example, in the 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;
/*......*/
Therefore, all the logs used in Calculator start with "Calculator.
For example, use the following method:
# Logcat &
<Get a log segment>
W/KeyCharacterMap (130): No keyboard for id 0
W/KeyCharacterMap (130): Using default keymap:/system/usr/keychars/qwerty. kcm. bin
I/ActivityManager (52): Displayed activity com. android. contacts/. DialtactsContactsEntryActivity: 983 MS
I/ARMAsse Explorer (52): generated scanline _ 00000077: 03545404_00000A04_00000000 [29 ipp] (51 ins) at [0x25c978: 0x25ca44] in 1764174 ns
I/ARMAssembler (52): generated scanline _ 00000077: 035151__0000000000000000000 [46 ipp] (65 ins) at [0x25d1c8: 0x25d2cc] in 776789 ns
D/dalvikvm (130 ):
GC freed 834 objects/81760 bytes in 63 ms
D/dalvikvm (52): GC freed 10588 objects/425776 bytes in 94 ms
Among them, W/I/D indicates the log level. "dalvikvm" and "ARMAssembler" are the names of different components (component). The numbers in the brackets indicate the process Number of log generation.
TIPS:
1. Use logcat & run in the background
2. Use-d to obtain all logs.
3. Use-f or redirect (> and>) to output to the file.
4. Use-s to set the filter to get the desired log.
Of course, the most important thing is to add the appropriate log in the program.
Many users who are new to Android development may encounter debugging problems. How can they quickly find the "Accident location" based on the error prompt "? In the eclipse + ADT development environment, there is no good way to directly track object content. By using the Android. util. Log class, you can find errors and print system log messages by yourself. It is an API for log output. We can insert a log for an object at any time in the android program, and then observe whether the logcat output is normal in ddms.
Common android. util. Log methods include log. V () log. D () log. I () log. W () and log. E (). Corresponds to verbose, debug, info, warn, and error according to the first letter. When we debug in ddms, the difference is not big, but the display color is different, but through the logcat filter, We can filter and display a certain type of, generally for the breakpoint of the execution error, in log. E is suitable. However, Android Development Network recommends that verbose and debug information only exist in development. The final version can only contain info, warn, and error logs. In actual use, we 'd better declare a String constant tag for each class, so that we can easily
Differentiate logs of different classes. For example:
Private Static final string tag = "myactivity ";
Next, we can use log to observe every detail in the android code as needed: log. E (TAG, "android123.com.cn"); but remember that the parameters of this log class are of the string type. Below is the logcat in ddms:
Finally, we will introduce the android log tool logcat.
Select Windows> show View> other...> Android> logcat in eclipse. After confirmation, the logcat display box is displayed, and the log added by the user is displayed here. Insert "log. I ("info", "This is a log"); "," This is a log "appears in the logcat display box when the statement is executed ". For detailed usage, see the android documentation.