Android Command line tool logcat detailed usage!

Source: Internet
Author: User
Tags system log

  Logcat is a command-line tool in Android that can be used to get log information for a program. See the bench for detailed instructions!

This post is from the network, the reference URL is: http://hi.baidu.com/%C9%C1%D2%AB%B5%C4%CB%AE%BD%A7/blog/item/7cc9e1d00715dc369b50271d.html.

"caused by copyright issues, LZ is not responsible for any! Reprint Please specify the source ",this post for technical exchanges, if you have any questions, please keep abreast reply! Thank you!

The Android log system provides the ability to record and view system debug information. Logs are recorded from a variety of software and some system buffers, and buffers can be viewed and used by the Logcat command.

first, the purpose of using the Logcat command:

1. You can use the Logcat command to view the contents of the System log buffer:
[ADB] logcat [<option>] ... [<filter-spec>] ...
For more information, see the Listing of logcat command Options , which have a detailed description of the Logcat commands.
2. You can also use the LOGCAT command on your computer or the remote ADB shell running on the emulator/device, or you can view the log output on your computer.
$ adb Logcat
You also use this:
# Logcat
Second, "filter" Log output:

each output of the Android log information has a label and its priority.

    • The label of the log is a brief indication of the original information of the system part. (For example, "View" is to view the system's label).
    • Priority has the following concentrations, which are arranged smoothly from low to High:
      • V -verbose (lowest priority)
      • D -debug
      • I -info
      • W -warning
      • E -error
      • F -fatal
      • S -silent (highest priority, on which nothing is ever printed)

In the first two columns when you run Logcat, you can see the LOGCAT tag list and priority level, which is labeled as:<priority>/<tag> .
Here is an example of a logcat output, which has the precedence of I, the tag is activitymanage:
I/activitymanager (585): Starting activity:intent {action=android.intent.action ...}
in order for the log output to reflect the level of management, you can also use filters to control the log output, and filters can help you describe the system's label level.
The filter statement is described in the following format:
tag:priority ..., tag means tag,
Priority is the lowest level of reporting that represents a label.
The priority of the log can be obtained from the above tag.
you can write tag:priority multiple times in the filter.
These instructions are only to the blank end.
Here's a few,
examples indicate that all log information is supported, except those labeled "Activitymanager" and those with priority "Info" above and labeled "MYAPP" and Priority "Debug" above. The priority report is the tag.
ADB logcat activitymanager:i Myapp:d *:s
The last element of the above expression, *:s , is to set all the labels as "silent", all logs only show "View" and "MyApp", and another use of *:s is to ensure that the log output is followed by The filter's description is limited and also allows the filters to be output to the log as an item.
The following filter statements refer to log information that shows priority warning or higher:
ADB logcat *:w
If you run Logcat on your computer, you can also android_log_tags for environment variables: Enter a parameter to set the default filter, compared to the remote Adbshell side .
Export android_log_tags= "activitymanager:i Myapp:d *:s "
It is important to note that the android_log_tags filter cannot output the log if it runs logcat through the remote shell or runs the emulator/device with the ADB shell logcat.

second, "control" log output format:

The log information includes many metadata fields including labels and precedence. You can modify the output format of the log so that a specific metadata field can be displayed. Information about the formatted output log can be obtained through the- v option.

    • brief  -display Priority/tag and PID of originating process (the D Efault format).
    • process  -display PID only.
    • tag  -display the Priority/tag only.
    • thread  -display Process:thread and Priority/tag only.
    • raw  -display the raw log message, with no other metadata fields.
    • time  -display the date, invocation time, Priority/tag, and PID of the O Riginating process.
    • long  -display all metadata fields and separate messages with a blank Li Nes.

when Logcat is started, you can specify the output format with the-v option:
[ADB] logcat [-v <format>]
here is the log format generated with thread :
ADB logcat-v Thread
Note that you only have the- v option to specify the output format options.

third, "View" available log buffers:

The Android log system has a loop buffer, and not all log systems have a default loop buffer. In order to get the log information, you need to start logcat with the- b option. If you want to use a loop buffer, you need to see the remaining loop buffer period:

    • Radio -View information about the buffer.
    • Events-View the buffer associated with the event.
    • Main-View the primary log buffer


The- B option uses the method:
[ADB] logcat [-b <buffer>]
The following example shows how to view the log buffer containing radio and telephony information:
ADB logcat-b Radio
Iv. View stdout and stderr
by default, the Android system has stdout and stderr (system.out and system.err ) output to /dev/null< /c6>, in the process of running the Dalvik VM, there is one system that can back up the log files. In this case, the system uses stdout and stderr and the priority I to record the log information.
This method specifies the path to the output, stops the emulator/device running, and then remotely enters the log by using the setprop command
$ adb shell stop
$ adb shell SetProp Log.redirect-stdio true
$ adb shell start
system until you turn off the simulator/device before the settings are retained, you can use the default settings on the emulator/device by adding /data/local.prop

v. List of LOGCAT commands:


Option Description
-b<buffer> Load a log buffer that can be used for viewing, such as event and radio. The default value is main. See viewing alternative Log buffersspecifically.
-C Clear the Log on the screen.
-D Output the log to the screen.
-f<filename> Specifies the <filename> of the output log information, which is stdout by default.
-G Outputs the specified log buffer and exits after output.
-N <count> Set the maximum number of logs <count>., the default value is 4 and needs to be used with the-r option.
-R <kbytes> Output log per <kbytes>, default value is 16 and needs to be used with the-f option.
-S Set the default filter level to silent.
-V <format> Set the log input format, the default is brief format,
To learn more about the supported formats, see controlling Log Output format.


     note:

      HTC DHD A9191 tutorial--DHD MIUI System Log Crawl Method!

    
      above Logcat detailed usage of Android! for reference! If you have any questions, please reply, thank you!

Android Command line tool logcat detailed usage!

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.