imcarlost 468f625df4 Add interactive filter UI and finish the Python 3 port
Logs now render in a full-screen view above a bottom prompt line when both
stdin and stdout are a terminal; typing live-filters the scrollback to lines
containing every typed word, case-insensitively. --plain restores the
previous streaming output, and piped usage is unaffected either way.

Also finishes the Python 3 port that #177 and #173 started:

- print(linebuf.encode('utf-8')) printed the bytes repr of every line instead
  of the line itself
- named_processes was still a lazily-exhausted map() object after #177
  wrapped catchall_package in list()
- piping adb logcat into pidcat crashed, since FakeStdinProcess read
  sys.stdin (str) where the rest of the script expected bytes
- indent_wrap could hang given a non-positive wrap area
- the shebang invoked python, which does not exist on systems that only ship
  python3
2026-07-20 09:23:55 -04:00
2017-04-25 17:23:24 +10:00
2013-06-12 10:28:50 -07:00

PID Cat

An update to Jeff Sharkey's excellent logcat color script which only shows log entries for processes from a specific application package.

During application development you often want to only display log messages coming from your app. Unfortunately, because the process ID changes every time you deploy to the phone it becomes a challenge to grep for the right thing.

This script solves that problem by filtering by application package. Supply the target package as the sole argument to the python script and enjoy a more convenient development process.

pidcat com.oprah.bees.android

Here is an example of the output when running for the Google Plus app:

Example screen

Interactive mode

When both stdin and stdout are a terminal, pidcat opens a full-screen filter UI instead of streaming: logs render above a bottom prompt line, and whatever you type live-filters the scrollback to lines containing every typed word, case-insensitively.

  • Backspace edits the query, Ctrl-U clears it.
  • Ctrl-L forces a redraw; the view also tracks terminal resizes.
  • Ctrl-C or Ctrl-D quits and restores your scrollback.

Pass --plain to get the original streaming output instead, e.g. for pidcat --plain com.oprah.bees.android | grep Foo. Piped input or output (adb logcat | pidcat com.oprah.bees.android, pidcat ... | less) always uses plain streaming, since there is no terminal to draw the UI on.

Install

Get the script:

  • OS X: Use Homebrew.

     brew install pidcat
    

    If you need to install the latest development version

    brew unlink pidcat
    brew install --HEAD pidcat
    
  • Arch Linux : Install the package called pidcat-git from the AUR.

  • Others: Download the pidcat.py and place it on your PATH.

Make sure that adb from the Android SDK is on your PATH. This script will not work unless this is that case. That means, when you type adb and press enter into your terminal something actually happens.

To include adb and other android tools on your path:

export PATH=$PATH:<path to Android SDK>/platform-tools
export PATH=$PATH:<path to Android SDK>/tools

Include these lines in your .bashrc or .zshrc.

Note: <path to Android SDK> should be absolute and not relative.

pidcat requires at least version 8.30 of coreutils. Ubuntu 20.04 LTS already ships with it, for 18.04 and below, coreutils can be upgraded from the focal repo by running the following:

sudo add-apt-repository 'deb http://archive.ubuntu.com/ubuntu focal main restricted universe multiverse'
sudo apt-get update
sudo apt-get -t focal install coreutils
S
Description
REPL version of the popular logcat script that shows log entries for a specific application package.
Readme
6.4 MiB
Languages
Python 78.7%
Shell 21.3%