When you’re building Android ROMs, sometimes the system fails to boot and leaves you to debug what is going on. When that happens, you turn to the ever so trusty adb logcat. But wait - the system is on a loop and is spewing logcats all over the place. What do you do?

Simple. You only look at the lines with the tag “E” in it. “E” for “Error”. Simple.

Until you realize, it’s like looking for needles in a haystack. There’s too many freaking logcat lines!

That’s why I wrote a parser to get rid of the useless lines.

Make a file called parse.py and copy the following contents into the file:

raw = open("crash.logcat", "r")
output = open("output.logcat", "w+")
# Loop through the entire file
for line in raw:
    # Line may be "----- <info>"
    if line[0] == "-":
        continue
    # A logcat entry is formatted like this:
    # <date (takes up two)> <int> <int> <error level> <service name> : <log>
    log = line.split()
    if log[4] == "E":
        output.write(line)

raw.close()
output.close()

OK, cool, so how do you use it? Simple. Just pipe logcat output like so:

adb logcat > crash.logcat

Then run the file like this:

python3 parse.py

The neatly formatted file should be at output.logcat. Take a look and see what the bug is. Hope this helped!