Android Studio's New Logcat Filter Syntax Is a Full Query Language
1. Core Changes in the New Version (Differences from the Old Version)
- Adopts a
field:valuekey-value pair syntax, supporting exact matching, regex matching, reverse exclusion, and multi-condition combinations; - Auto-suggestion prompts (the dropdown list in your screenshot is the syntax hint);
- 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
age:10m: Only show logs from the last 10 minutesis:stacktrace: Only show crash stack trace logsline:xxx: Match any content within a log line (equivalent to a global search)
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
- Only view permission module logs
plaintext
package:mine tag~:Permission
- View permission + data center modules simultaneously
plaintext
package:mine tag~:PermissionUtils|DataCenterUtils
- Only view vehicle property related errors
plaintext
package:mine tag~:CarService level:error
- 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)
- Enter the filter statement;
- Click the star⭐ button on the left side of the input box to save as a preset filter;
- Next time, just select from the dropdown without retyping the syntax.
6. Common Pitfalls & Tips
- Fuzzy matching must include
~Writingtag:Permissiondirectly only matches TAGs exactly equal toPermission, notPermissionUtils; to include keywords, you must usetag~:Permission. - Use
|to separate regex for matching multiple TAGs simultaneouslytag~:A|B|Cmatches multiple TAGs at once, no need to write multiple filter statements. - Universal quick noise-reduction prefix Add
package:mineat the very beginning of all filter statements to directly filter 90% of system and third-party process junk logs. - 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.
- Quotation marks for TAGs/content with spaces When a TAG contains spaces:
tag:"My Permission Util" - Escaping special regex characters If a TAG contains
. |or similar symbols, escape them with a backslashtag~:CarService\|CarProperty
7. Quick Reference Cheat Sheet
- Exact match:
field:full_value - Fuzzy search TAG / package:
field~:keyword - Exclude logs:
-field:value/-field~:keyword - Only view your own app: Always prefix with
package:mine - Stack multiple conditions: Separate multiple filter statements with spaces