Android debugging-Log

Source: Internet
Author: User

Android Application Development requires assistance with the output information in log files during debugging.

1. Android Application debugging

By default, Android applications cannot be debugged. (eclipse) will prompt the following message: "application" XXX "does not have the attribute 'destggable' set to true in its manifest and cannot be debugged"

You need to modify the debuggable attribute in the manifest file to make the value true before debugging.

Ii. log information 1. Output log information

Android provides a static log class and five static log methods. V () (detailed), log. D () (Debug), log. I () (Information), log. W () (warning), log. E () (error) is used to write messages to log files on the simulator. If you run logcat on ddms, you can view messages in real time.

(1) log information level
  • 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.

(2) Output log information

Add import Android. util. log to the application;

Use the static method of this class,

      1. Log. D (string tag, string MSG );
    1. Log. I (string tag, string MSG );
    2. Log. W (string tag, string MSG );
    3. Log. E (string tag, string MSG );
  • Where: A tag is an identifier and can be any string (usually a static constant or a class name + method name). It is used to provide a filter condition when viewing logs, to facilitate tracing information output.
  • MSG is the content of log information.

Use the system. Out. println (); statement in the application to output information to the log file (rather than to the console ).

2. View logs in eclipse

The procedure is as follows:

(1) Windows ==> preferences ==> Android ==> ddms ==> logging level

(Set the log level. The selected values are not displayed .)

(2) Windows ==> show view ==> Android ==> logcat

(3) display the logcat column.

3. Use the logcat command line tool to view logs

Logcat is a command line tool in Android. You can use it to obtain the log information of the program.

Use logcat as follows: 

Logcat [Options] [filterspecs]

Options includes:

  • -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.
  • Filter format: <tag> [: Priority], where <tag> indicates the log component,

Priority is as follows:

  • V verbose --------------------------------------- log. V ()
  • D debug ----------------------------------------- log. D ()
  • I info --------------------------------------------- log. I ()
  • W warn ----------------------------------------- log. W ()
  • E error ------------------------------------------ log. E ()
  • F fatal
  • S silent
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.