In the Android development process, it is unavoidable to debug, whether it is debug, or Android Logcat, or DDMS, etc., use properly will give us a multiplier effect of development. Usually all kinds of debugging means have tried, but a lot of things, especially some orders, used to forget, think up to use Google again; so I'm going to put these things together for later review, but also a summary of some experience
Logcat1. Viewing Android's Logcat logs
The Android system generates a lot of logs at run time to facilitate debugging by developers. The Logcat log is stored in the shampoo memory, and the system modules and application output logs are uniformly placed in a circular queue in memory from the start of the system. Keeping logs in system memory ensures that the logging function does not affect the speed of the application, and the ring queue is to avoid unlimited log growth (ring/users/adison/octopress/source/_posts/2014-10-18- Volley-cachefen-xi.markdown structure, the last record will be written at the first position when it is full.
You can use "adb logcat" to view this in-memory log
You can use the methods in the log class to output Logcat logs in your app. Here are a few common log functions:
- V (string,string) logging of redundancy levels
- D (string,string) logging of debug levels
- I (string,string) logging information level logs
- W (string,string) Logging of warning levels
- E (string,string) logging of Run error levels
Their priority levels are low to high and are V < D < i< w< E
2. Filtering Logcat logs 2.1. Priority-Based
ADB Logcat provides additional functionality to filter logs based on the log priority level. Use for ADB logcat *:#, where # is one of the above levels.
All priorities automatically contain a higher priority than it is, so adb logcat : w contains warnings, errors, and fatal errors. When the app crashes, you can use ADB logcat : E to see the cause of the problem without having to look at the irrelevant debug logs. However, when you provide the log to the developer, you should include all the logs (do not set any filters), as the actual cause of the problem can often be found through debug logs.
When you debug your app, you can use the filters for < tags >:< priority > To remove many unrelated logs. The < label > condition tells Logcat to output only the log with the label, while the "priority" condition tells Logcat to output the lowest priority of the log, you can set up multiple filters at the same time on the Logcat command line, each with a space separated. The following command only outputs a variable labeled "Activitymanager", with a priority higher than the information level, labeled "DALVIKVM", with a priority higher than the "debug" level message, and the final "*:s" filter to mask all log messages with other labels.
adb logcat ActivityManager:I dalvikvm:D *:s
2.2. Content-based
You can also filter based on "content". For example, you want to collect all the journal lines that refer to the term "Google". You can do this:
adb logcat | grep Google
3. Other Tips Empty
If you find that the screen is full of useless log information, but you still need a detailed log, you can use ADB logcat-c to clear the log buffer. It resets the log and displays only the contents of the log after it is reset.
Logcat for error tracking
adb shelllogcat -d -f /sdcard/logcat.log *:E
-D Dump Logcat content
-F Specify the log save location
*:e Output error Log
Android Debugging Logcat