Logcat detailed usage of Android

Source: Internet
Author: User
Tags system log

Directory (?) [+]

    1. Using the Logcat command
    2. Filtering log output
    3. Control log Output format
    4. View available Log buffers
    5. View stdout and stderr
    6. Logcat Command List

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 logcat viewed and used by commands.

Uselogcat Command

You can use logcat the command to view the contents of the System log buffer:

Logcat [<option>] ... [<filter-spec>] ...

See the listing of logcat command Options for A detailed description of LOGCAT commands.

You can also use commands on your computer or on the remote ADB shell that runs on the emulator/device, or you logcat can view the log output on your computer.

Logcat

You also use this:

Logcat

Filtering 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 of information you can see logcat the list of tags and the priority level when you run Logcat, 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 as tag:priority ... tag a label, which priority is the lowest level of reporting for the label. The priority of the log can be obtained from the above tag. You can write multiple times in the filter tag:priority .

These instructions are only to the blank end. Here is an example that shows support for all log information except those labeled "Activitymanager" and the priority "Info" above and labeled "MYAPP" and Priority "Debug" above. The priority report is the tag.

Logcat activitymanager:i Myapp:d *:s

The last element of the expression above, *:S is to set all the labels as "silent", all logs only show "View" and "MyApp", *:S another use is to be able to ensure that the log output is in accordance with the filter description limit, Also let the filter output to the log as an item.

The following filter statements refer to log information that shows priority warning or higher:

Logcat *:w

If you are running on your computer logcat , you can also ANDROID_LOG_TAGS set the default filter for environment variables: Enter a parameter compared to the remote Adbshell side.

Export android_log_tags= "activitymanager:i Myapp:d *:s "

It is important to note that ANDROID_LOG_TAGS if the filter is running through a remote shell logcat or running the adb shell logcat emulator/device, the log cannot be output.

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 -v the output log can be formatted with the option.

  • brief-display Priority/tag and PID of originating process (the default 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 and no other metadata fields.
  • time-display the date, invocation time, Priority/tag, and PID of the originating process.
  • long-display all metadata fields and separate messages with a blank lines.

When started logcat , you can specify the -v output format with the option:

Logcat [-v <format>]

The following are thread the resulting log formats:

Logcat-v thread

Note that you can only have -v options to specify the output format option.

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 with the -b option logcat . If you want to use a loop buffer, you need to see the remaining loop buffer period:

    • radio-View the relevant information for the buffer.
    • events-View the buffer associated with the event.
    • main-View the primary log buffer

-bHow to use options:

Logcat [-b <buffer>]

The following example shows how to view the log buffer containing radio and telephony information:

Logcat-b Radio

View stdout and stderr

By default, the Android system has a stdout and stderr ( System.out and System.err ) output to /dev/null , in the process of running the Dalvik VM, there is a system that can back up the log files. In this case, the system uses the stdout and stderr and the priority I to record the log information

In this way, you specify the path to the output, stop the emulator/device that is running, and then enter the log remotely by using a setprop command

$ adb shell stop$ adb shell setprop log.redirect-stdio true$ adb shell start

System until you close the simulator/device before the settings will remain, can be added by /data/local.prop using the emulator/device default settings

logcat Command List
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 buffers specifically.
-c Clear the Log on the screen.
-d Output the log to the screen.
-f <filename> Specifies the output log information <filename> , which is the default stdout .
-g Outputs the specified log buffer and exits after output.
-n <count> Sets the maximum number of logs <count> . The default value is 4 and needs to be used with the -r option.
-r <kbytes> <kbytes>output log per hour, default value of 16, needs to be -f used with options.
-s Set the default filter level to silent.
-v <format> To set the log input format, the default is brief format, to know more supported formats, see Controlling log Output format.

Logcat detailed usage of Android

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.