A shell script for limiting logcat output to a single package
I like to view the logcat output for just my app and nothing else. Here's a
small shell script I use for this. Consider placing it in your .zshrc
or
.bashrc
so that it's always available.
function logcat {
pkg="$1"
shift
if [ -z "$pkg" ]; then
>&2 echo 'Usage: logcat pkg ...'
return 1
fi
uid="$(adb shell pm list package -U $pkg | sed 's/.*uid://')"
if [ -z "$uid" ]; then
>&2 echo "pkg '$pkg' not found"
return 1
fi
adb logcat --uid="$uid" "$@"
}
Usage is:
# replace com.example.android with your app's package name
$ logcat com.example.android
Since this script filters for uid rather than pid, it will continue showing output even if your process is restarted. Any additional args will be passed on to logcat, so you can specify tags, etc.
If you enjoyed this post, please let me know on Twitter or Bluesky.
Posted September 17, 2023.
Tags: #android