LoginSignup
1
0

More than 3 years have passed since last update.

Android Studio Logcat regex expressions for efficient debugging

Posted at

Logcat provides several default filter options (Verbose, Info, Debug etc) and a simple pattern match filter, but the regex filter is the most powerful option for customizing logcat output. Here, I provide 3 useful patterns that have been frequently used to search the logcat more efficiently.

1. Basic INCLUDE filter:

(logging|FA)

where logcat will only show lines containing the expressions separated by "|" (case-insensitive).

For example, "logging" may be a unique log identifier for your application, and FA is the output from the Firebase Analytics library

2. INCLUDE exact string filter (case-sensitive)

(?i)\bFA\b

here, we find logs that match FA exactly e.g. FA, FA-SVC from the Firebase Analytics library, and not any line that includes FA, Fa, fa etc

3. EXCLUDE filter by message type/source

Alternatively, if we want to display most of the logs (because we want to observe any unexpected library crashes or device warnings), it is better to EXCLUDE only those messages we can confidently ignore for the current session.

e.g.

^(?:(?!D/|I/|E/|W/|V/|Wifi|audio_hw_extn).)*$\r?\n?

where

  • E/ corresponds to Error messages, I/ corresponds to Info messages, etc..
  • Wifi, audio_hw_extn corresponds to any message containing these common keywords

Examples of message sources that frequent pollute the logcat and may not be useful for debugging include:
- GnssLocationProvider
- Bundle
- WifiService
- audio_hw_extn
- sensors-hal
- FA|FA-SVC (verbose logging from Firebase Analytics, if not disabled in the application code)

One could also copy their un-filtered logcat to an online text analyzer e.g. https://www.online-utility.org/text/analyzer.jsp to find the most common sources of logs.

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0