跪拜 Guibai
← Back to the summary

Android Studio's New Logcat Filter Syntax Is a Full Query Language

1. Core Changes in the New Version (Differences from the Old Version)

  1. Adopts a field:value key-value pair syntax, supporting exact matching, regex matching, reverse exclusion, and multi-condition combinations;
  2. Auto-suggestion prompts (the dropdown list in your screenshot is the syntax hint);
  3. Supports stacking multiple conditions with spaces, all taking effect simultaneously (intersection logic).

Basic Symbol Rules (Understanding tag~: package~: in the Screenshot)

Table

Symbol Function Example
field:xxx Exact full match, hits only when completely equal tag:PermissionUtils only matches TAGs exactly equal to PermissionUtils
field~:xxx Regex fuzzy match (all entries with ~ in the screenshot are this) tag~:Permission matches all TAGs containing Permission
-field:xxx Reverse exclusion, does not display this log -tag:System filters out logs with TAG=System
-field~:xxx Regex exclusion, removes logs matching the regex -tag~:System|UI filters both System and UI TAGs simultaneously

2. All Built-in Filter Fields (High Frequency Daily Use)

1. package Package Name Filtering (Most Common)

plaintext

# Only view logs from the currently debugging app (one-click filter for system noise, must remember)
package:mine

# Exact match full package name
package:com.cars.adapterservice.china

# Regex match package name (contains a certain package path segment)
package~:cars.adapter

# Exclude other third-party packages
package:mine -package:com.android

The package:mine, package~:com.cars.adapterservice.china in the screenshot use this syntax.

2. tag TAG Filtering (The log.xxx You Care About Most)

Exact Match (Full TAG)

plaintext

# Only view the PermissionUtils TAG
tag:PermissionUtils
# Only view DataCenterProvider
tag:DataCenterProvider

Regex Fuzzy Match (The tag~: series in the screenshot, matches TAGs containing keywords)

plaintext

# All TAGs containing Permission (PermissionUtils, PermissionTest will all appear)
tag~:Permission

# Match multiple TAGs simultaneously (regex | separator)
tag~:PermissionUtils|DataCenterUtils|CarService

# Match all TAGs with the prefix CarService
tag~:^CarService.*

# Exclude specified TAGs
package:mine -tag~:System|ActivityManager

The tag~:PermissionUtils, tag~:CarService|CarPropertyViewModel in the screenshot are regex multi-TAG matching.

3. level Log Level Filtering

Levels: verbose / debug / info / warn / error / assert

plaintext

# Only view Error level logs
level:error

# Only view Warn+Error
level~:warn|error

# Filter out Verbose debug logs
-level:verbose

level:error in the screenshot means only showing error logs.

4. message Log Content Filtering (Search text printed in logs)

plaintext

# Exact match full log content text
message:"Loading data failed"

# Regex fuzzy search for logs containing keywords
message~:Permission Request|Property Change

# Filter out useless prints
-message~:Heartbeat Packet

5. process Process Filtering (Multi-process Projects)

plaintext

# Match process name
process:car_service
# Regex match multiple processes
process~:adapter|car

6. Other Auxiliary Fields

3. Multi-Condition Combination Syntax (Most Practical for Daily Development)

Multiple conditions are separated by spaces, and logs are displayed only when all conditions are met simultaneously (intersection).

Example 1: Only view own app, Error level, TAG containing CarService

plaintext

package:mine level:error tag~:CarService

Example 2: Only view permission-related TAGs, filter system logs

plaintext

package:mine tag~:Permission

Example 3: Only view CarProperty related logs, exclude system prints

plaintext

package:mine tag~:CarProperty -tag~:System

Example 4: Monitor multiple business TAGs simultaneously, only view Debug and above

plaintext

package:mine tag~:PermissionUtils|DataCenterProvider level~:debug|info|warn|error

4. Practical Examples for Your Screenshot Scenario (Automotive Project)

Your log TAGs: PermissionUtils, DataCenterUtils, CarService|CarPropertyViewModel

  1. Only view permission module logs

plaintext

package:mine tag~:Permission
  1. View permission + data center modules simultaneously

plaintext

package:mine tag~:PermissionUtils|DataCenterUtils
  1. Only view vehicle property related errors

plaintext

package:mine tag~:CarService level:error
  1. Filter all system noise logs, keep only business TAGs

plaintext

package:mine tag~:PermissionUtils|DataCenterUtils|CarService -tag~:android|System

5. Save Frequently Used Filter Templates (No Need to Re-type Each Time)

  1. Enter the filter statement;
  2. Click the star⭐ button on the left side of the input box to save as a preset filter;
  3. Next time, just select from the dropdown without retyping the syntax.

6. Common Pitfalls & Tips

  1. Fuzzy matching must include ~ Writing tag:Permission directly only matches TAGs exactly equal to Permission, not PermissionUtils; to include keywords, you must use tag~:Permission.
  2. Use | to separate regex for matching multiple TAGs simultaneously tag~:A|B|C matches multiple TAGs at once, no need to write multiple filter statements.
  3. Universal quick noise-reduction prefix Add package:mine at the very beginning of all filter statements to directly filter 90% of system and third-party process junk logs.
  4. To switch back to the old Logcat (nostalgia) File → Settings → Experimental → Logcat → Uncheck Enable new Logcat tool window, restart AS to restore the old version.
  5. Quotation marks for TAGs/content with spaces When a TAG contains spaces: tag:"My Permission Util"
  6. Escaping special regex characters If a TAG contains . | or similar symbols, escape them with a backslash tag~:CarService\|CarProperty

7. Quick Reference Cheat Sheet

  1. Exact match: field:full_value
  2. Fuzzy search TAG / package: field~:keyword
  3. Exclude logs: -field:value / -field~:keyword
  4. Only view your own app: Always prefix with package:mine
  5. Stack multiple conditions: Separate multiple filter statements with spaces