Woodchopper

Sean Borg June 25, 2024 #Rust #android #programming

Goal

Split logs from logcat without a device accessible.

Why

A client of mine makes an Android device with pre-bundled apps, my main job was working on these apps but whenever we captured logs from a customer they were a bit of a nightmare to pull apart

Android logs from a simple logcat -d don’t print out the package ID they come from, instead it outputs the PID and tag, I would love to know how Android studio filters of package ID! The tag we can control and filter on but it’s generally recommended to set the tag as the class name (todo confirm its recommended and find a link ), I find due to Android studio filtering with package ID in development I often don't pay much attention to the tags (I admit this is probably the better solution).

https://developer.android.com/reference/android/util/Log

Tip: A good convention is to declare a TAG constant in your class: private static final String TAG = "MyActivity"; and use that in subsequent calls to the log methods.

Aaa although Google never explicitly suggests using the class name it is accidentally implied, and timber automatically uses the method name as the tag. I find method name often is way too short lived for a tag ideally I need to come up with a better convention but since I am inheriting a code base this is not so easily changed.

A very similar application is “PID cat” which works great if you are debugging a device you have on the desk, but this falls down if someone is sending you system logs and you have no access to the device. This is where woodchopper comes in splitting all logs by PID and then from there attempts to match those logs to package IDs. Woodchopper can do this 2 ways automatically by matching the PID on application start from the ( todo file in demon that does this), or semi automatic by you providing some known logs that your application emits and matching on them to give package id

Who is this for… I’m not so sure really I realise the reason I’m in this situation is because I’m writing with an Android manufacturer and they make some built in apps but in normal operation you wouldn’t be shipping with so much logging

Differs from https://github.com/JakeWharton/pidcat As this requires the device to be reachable via adb and calls the package manager during running to get the PID to filter on

Where

https://gitlab.com/seam345/woodchopper