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,
- Log. D (string tag, string MSG );
- Log. I (string tag, string MSG );
- Log. W (string tag, string MSG );
- 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