Colored logcat script which only shows log entries for a specific application package.

Overview

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

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
Comments
  • Shebang env invalid option 'S'

    Shebang env invalid option 'S'

    Executing pidcat.py on Ubuntu 18.04.4 LTS results:

    /usr/bin/env: invalid option -- 'S'
    Try '/usr/bin/env --help' for more information.
    

    Shebang was changed in https://github.com/JakeWharton/pidcat/commit/e5fa59974b312727c503e42b1bf94e1ecf3e556d after changing it back to #!/usr/bin/python -u it starts to work again.

    I have env (GNU coreutils) 8.28 installed. Should be the default from Ubuntu. Looking in env --help doesn't list the -S at all, only the following:

    Usage: env [OPTION]... [-] [NAME=VALUE]... [COMMAND [ARG]...]
    Set each NAME to VALUE in the environment and run COMMAND.
    
    Mandatory arguments to long options are mandatory for short options too.
      -i, --ignore-environment  start with an empty environment
      -0, --null           end each output line with NUL, not newline
      -u, --unset=NAME     remove variable from the environment
      -C, --chdir=DIR      change working directory to DIR
          --help     display this help and exit
          --version  output version information and exit
    
    A mere - implies -i.  If no COMMAND, print the resulting environment.
    
    GNU coreutils online help: <http://www.gnu.org/software/coreutils/>
    Full documentation at: <http://www.gnu.org/software/coreutils/env>
    or available locally via: info '(coreutils) env invocation'
    
    opened by hakovala 13
  • Print line if we have not seen any pids created yet

    Print line if we have not seen any pids created yet

    This specifically handles the case where you get a log snippet that may not have any pid creation lines in it and pidcat ends up filtering everything out. In this case we just print the line if we haven't seen any pids yet.

    An alternative would be allowing filter by pid, however I find grep works fine for that.

    opened by brennantaylor 13
  • Android M changed logcat output => no logs displayed

    Android M changed logcat output => no logs displayed

    On the M preview 1, with a Nexus 6: Alas more changes :| It seems to use the same "Start proc" format as 5.1, but the (default) columns have changed.

    An example log line: 06-06 12:14:46.355 372 18641 D audio_hw_primary: disable_audio_route: reset and update mixer path: audio-record

    Regex + group changes that fix output: LOG_LINE = re.compile(r'^\S+\s\S+\s+(\d+)\s+\S+\s([A-Z])\s([^:]+)\s(.+)$') owner, level, tag, message = log_line.groups()

    Not sure how you'd like to fit them in with the existing code (if you have any intention of fixing this for preview releases), but I figured I'd at least try to save some effort :)

    opened by Groxx 9
  • Filter By Tag

    Filter By Tag

    I added this code before I found the "--always-display-tags" switch which allows for useful grepping. I don't know if it's useful, but thought I would pass it along anyways.

    opened by adstro 9
  • Add timestamps to each message

    Add timestamps to each message

    Enabled with the --timestamp flag. Fixes #9.

    All I've done is rebase @marczych's commit in PR #34 to the latest master. I've also removed the short -t flag because it's already being used for tags. Let me know if any other changes are required to get this merged in.

    opened by vickychijwani 8
  • OSError: [Errno 2] No such file or directory

    OSError: [Errno 2] No such file or directory

    Hey Jake,

    I'm on a macbook pro, python installed. I installed pidcat via brew, everything seemed to work fine. But when I want to launch pidcat, I have this error (OSError: [Errno 2] No such file or directory).

    I'm not sure if it's something from pidcat or my computer. I asked Google but it couldn't give any good answer.... so...

    Do you have any idea ?

    mathieu$ pidcat com.mdb.android.russianroulette Traceback (most recent call last): File "/usr/local/bin/pidcat", line 150, in adb = subprocess.Popen(adb_command, stdin=PIPE, stdout=PIPE, stderr=PIPE) File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 711, in init errread, errwrite) File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 1308, in _execute_child raise child_exception OSError: [Errno 2] No such file or directory

    opened by mathieudebrito 6
  • added option to always display tag name, so that we can pipe its output ...

    added option to always display tag name, so that we can pipe its output ...

    Hey,

    I wanted to filter dalvikvm logs from pidcat output. So, it would be nice to have an option to always display tagname, so that we can pipe its output to grep and filter certain tags.

    ./pidcat.py -l D  --always-display-tags com.trhura.android.somepackage | grep -v -e "dalvikvm"
    
    opened by trhura 6
  • Support custom terminal widths (required to support pipes)

    Support custom terminal widths (required to support pipes)

    Right now piping to non-screen sources are not supported since they would fail when try to get the width of a terminal. This adds the flexibility to add a terminal_width parameter so that we don't have to determine the width and trigger the IOError.

    opened by edisonw 5
  • Pidcat doesn't seem to be working with my Nexus 6P

    Pidcat doesn't seem to be working with my Nexus 6P

    Running on OS X 10.11.1 in iTerm2 connected to a Nexus 6P

    Issue: pidcat doesn't output anything

    STR:

    • Connect 6P
    • Run pidcat

    Interesting things to note (maybe):

    • adb logcat does have expected output
    • when I disconnect my device after starting pidcat, the pidcat process automatically stops. It seems to recognize there's a device attached.
    • adb devices shows that the device is recognized
    opened by loeschg 4
  • Handle alternative start proc log line

    Handle alternative start proc log line

    Add support for an alternative log format for starting new processes. Also reverts the "print line if we have not seen any pids" diff, which it sounds like was motivated by this flaw? Either way that change is fairly harmful to what I believe is normal use of pidcat.

    opened by ahupp 4
  • pidcat sometimes can't parse adb output

    pidcat sometimes can't parse adb output

    Every now and then it seems that adb spits out a line that pidcat chokes on:

    dalvikvm  D  Trying to load lib /data/app-lib/com.motorola.aon-1/libpartial_display.so 0x41fbba88
              D  Added shared lib /data/app-lib/com.motorola.aon-1/libpartial_display.so 0x41fbba88
    Traceback (most recent call last):
      File "./pidcat.py", line 226, in <module>
        if LOG_LEVELS_MAP[level] < min_level:
    KeyError: u'S'
    
    opened by paleozogt 4
  • On Python3, color codes are printed instead of colors

    On Python3, color codes are printed instead of colors

    I'm running on Bash 5.1.16 and have the TERM variables set appropriately:

    $ env | grep TERM
    COLORTERM=truecolor
    TERM=xterm-256color
    

    If I run pidcat with python3, I get output like this:

    b'\x1b[37m        ActivityManager\x1b[0m \x1b[30;102m I \x1b[0m Process com.samsung.android.app.galaxyfinder:appservice (pid 18912) has died: fg  SVC (127,1420)'
    b'\x1b[33matibilityChangeReporter\x1b[0m \x1b[30;104m D \x1b[0m Compat change id reported: 135634846; UID 10300; state: DISABLED'
    b'                        \x1b[30;104m D \x1b[0m Compat change id reported: 143937733; UID 10300; state: ENABLED'
    

    but if I run with python2, then I get colorized output as expected.

    If I delete the .encode(utf-8) from the final print statement, then it works as expected on both Python2 and Python3, but I suspect this might cause problems on some systems if locale isn't utf-8.

    $ git revert -n 6b6034ab67
    Auto-merging pidcat.py
    $ git reset
    Unstaged changes after reset:
    M	pidcat.py
    $ git diff
    diff --git a/pidcat.py b/pidcat.py
    index 6a23786..4a2b42f 100755
    --- a/pidcat.py
    +++ b/pidcat.py
    @@ -359,4 +359,4 @@ while adb.poll() is None:
         message = matcher.sub(replace, message)
     
       linebuf += indent_wrap(message)
    -  print(linebuf.encode('utf-8'))
    +  print(linebuf)
    
    opened by bobpaul 0
  • Getting package list with

    Getting package list with "ls /data/data" not working on recent Android versions

    I'm not getting autocompletion for package names with Android 12 emulator.

    The reason is that this command fails:

    adb $device_selected shell ls /data/data 2>/dev/null
    

    because of a permissions issue:

    adb shell ls /data/data
    ls: /data/data: Permission denied
    

    This replacement works fine for me:

    local apks=$(adb $device_selected shell pm list packages 2>/dev/null | sed "s/package://g" | tr '\n' ' ' | tr -d '\r')
    
    opened by kmansoft 1
  • `pidcat` installed via `brew` no longer works on macOS 12.3, due to Python 2 having been removed

    `pidcat` installed via `brew` no longer works on macOS 12.3, due to Python 2 having been removed

    Hey!

    First off, thank you for the great util, Jake. And all the other cool stuff you've built througout the years.

    I'm having an issue where pidcat, installed from brew, can no longer run on macOS 12.3. I believe this is because of Python 2 having been removed on this version of macOS.

    I'm getting the following output, when attempting to run pidcat:

    ~ pidcat
    zsh: /opt/homebrew/bin/pidcat: bad interpreter: /usr/bin/python: no such file or directory
    

    This in turn is caused by https://github.com/JakeWharton/pidcat/blob/44b4a106bb25776cbb551044b303520a07a51c1e/pidcat.py#L1:

    #!/usr/bin/python -u
    

    On macOS 12.3, /usr/bin/python does not exist - only /usr/bin/python3.

    Running on the latest development version (as listed in the current README.md, does not solve the issue, as it still looks for python, which still does not exist.

    One alternative that could resolve the issue would be to update pidcat to explicitly try to use python3, but this would have some less desirable backwards compatibility issues, perhaps.

    opened by oscarnylander 18
  • Adjust README for Flutter Android SDK setup

    Adjust README for Flutter Android SDK setup

    The README.md suggests the following to be added to the shell config to enable pidcat:

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

    This step is unnecessary for machines that have the ANDROID_SDK_ROOT environment variable set up in the shell config for Flutter developers. We can modify the documentation to account for this since Android Studio also supports Flutter development.

    opened by LemonSpike 0
Owner
Jake Wharton
Jake Wharton
android logcat

android logcat

Ji Sungbin 3 Dec 2, 2022
🌼APM, (Application Performance Management) tool for kotlin/java application.

??APM, (Application Performance Management) tool for kotlin/java application.

Espresso 4 Mar 8, 2022
This app will show grid overlay over whole system which helps you to verify your excellent app design.

GridWichterle for Android This app will show grid overlay over whole system which helps you to verify your excellent app design. Download: What is the

Inmite s.r.o. 407 Jan 9, 2023
btrace(AKA RheaTrace) is a high performance Android trace tool which is based on Systrace

btrace README 中文版 btrace(AKA RheaTrace) is a high performance Android trace tool

Bytedance Inc. 1.2k Jan 4, 2023
Goreinu allows to copy application files on sdcard.

Goreinu Goreinu allows to copy application files on sdcard.(/data/data/package_name/... -> /sdcard/Goreinu/package_name). Getting started In your buil

Shinnosuke Kugimiya 32 Dec 11, 2021
An easy way to customize your log in Android,including output to console, writing log to file in high performance way and so on

EasyLog An easy way to customize your log in Android,including output to console, writing log to file in high performance way and so on. 1. Initializa

Taylor 40 Dec 8, 2022
Techbee e.U. 62 Jan 31, 2023
A Sudoku Application using Graph Data Structure(Directed Colored Graph).

Project Overview Graph Sudoku is an application which was created with three goals in mind: Teach myself Jetpack Compose Teach myself Graph Datastruct

null 3 Aug 10, 2022
A Gradle plugin to help analyse the dependency between modules and run tasks only on modules impacted by specific set of changes.

Change Tracker Plugin A Gradle plugin to help analyse the dependency between modules and run tasks only on modules impacted by specific set of changes

Ismael Di Vita 110 Dec 19, 2022
A smart colored time selector. Users can select just free time with a handy colorful range selector.

Colored Time Range Selector A smart colored time range selector. Users can select just free time with a handy colorful range selector. Screen Shots Fe

Ehsan Mehranvari 154 Oct 3, 2022
An android custom view that displays a circle with a colored arc given a mark

MarkView An android custom view that displays a circle with a colored arc given a mark. Usage Add as a dependency compile 'com.github.xiprox.markv

İhsan Işık 200 Nov 25, 2022
Android app that displays the logcat buffer in a system overlay window

Ghost Log Ghost Log is an Android application that displays the device logcat buffer in a system overlay window. NOTE: Device root (superuser) access

Jeff Gilfelt 378 Nov 15, 2022
Timber + Logger Integration. Make Logcat Prettier, show thread information and more.

Pretty Timber Android Logcat Timber + Logger Integration Video Instructions: https://youtu.be/zoS_i8VshCk Code App.kt class App : Application() {

Awesome Dev Notes | Android Dev Notes YouTube 29 Jun 6, 2022
Kotlin Multi Platform Logger, for android an ios : Logcat & print

Multiplatform Preferences Use a single object : Logger in your kotlin shared projects to display logs Note you can also use it in your real code on An

Florent CHAMPIGNY 49 Aug 22, 2022
A `adb logcat` wrapper

rogcat ...is a adb logcat wrapper. The Android Debugging Bridge (adb) is the default way to interact with a Android device during development. The log

Felix Obenhuber 176 Dec 31, 2022
android logcat

android logcat

Ji Sungbin 3 Dec 2, 2022
A logger with a small, extensible API which provides utility on top of Android's normal Log class.

This is a logger with a small, extensible API which provides utility on top of Android's normal Log class. I copy this class into all the little apps

Jake Wharton 9.9k Jan 8, 2023
A logger with a small, extensible API which provides utility on top of Android's normal Log class.

This is a logger with a small, extensible API which provides utility on top of Android's normal Log class. I copy this class into all the little apps

Jake Wharton 9.8k Dec 30, 2022