Digging into logcat on-device

Wes Alvaro
1 min readJun 22, 2021

We all know how to run adb logcat and some of us might have used a flag or two or piped the output to grep but what do we do if we need to access the contents of the log from on-device (e.g. when looking for the output file of our thread traces during a UIAutomator test)?

We can access the logcat from shell via the (you probably guessed it)logcat command. This command is documented quite extensively and provides quite a fair amount of options. It’s fairly straightforward to filter our log when we need to reconcile the results of some command we’ve previously executed in the shell.

If we’re trying to get the location to our thread traces, we can use some options to logcat and a few piped on commands.

# logcat -d -s -b main "tombstoned:E" | \
tail -n+2 | \
tail -n1 | \
awk '{ print $NF }
/data/anr/trace_12

The built-in logcat comes with lots of options but I also wanted to change the output format and create profiles based on my debugging task. To handle that, I created a simple utility with Go. I’m also working on an interactive, Curses-based version but the library I’m using for that right now has some bugs. Maybe you’ll find it’s useful for you, too!

--

--

Wes Alvaro

I'm a software engineer currently working on an Android app you might use everyday.