← Table of Contents

Rubber Duck Debugging / 3 of 5 / 1 dilihat

Reading Android Logcat Properly

Reading Android Logcat Properly, Not Just Hunting for Red Text

A lot of newer developers open Logcat for exactly one reason: find the red line. Once they spot it, they skim it, then close the panel again. But Logcat is actually one of the richest sources of evidence we have — as long as you know how to read it.

Log Levels and When to Use Them

Android has six log levels, from noisiest to most critical:

V = Verbose  → fine-grained internal tracing
D = Debug    → useful during development
I = Info     → notable but normal events (e.g. a request was sent)
W = Warning  → something suspicious but not yet crashing
E = Error    → something clearly wrong that needs attention
F = Fatal    → a crash, the app stops

A common mistake: developers log everything as Log.d, without thinking about which level actually fits. In production, that makes it hard to tell what actually matters from what's just noise. Get in the habit of using the right level — Log.w for "weird but still running," Log.e for caught exceptions that still need to be known about.

Filtering: Package, Tag, and Keyword

Raw Logcat output from a device can spit out thousands of lines per second, much of it from the system and other apps. Three filters get used most often:

  • Filter by package — show only logs from your own app's process. This is the mandatory first step, or you'll drown in system noise.
  • Filter by tag — if you're consistent with clear tags (e.g. LOGIN_FLOW, PLAYER_STATE), you can focus on one specific flow without noise from unrelated parts of the app.
  • Filter by keyword — useful when hunting a specific value, like searching for userId= to trace every log tied to a particular user.

Timestamp, Thread, and Process ID — Easy to Ignore, Crucial When Timing Matters

This is the part junior developers skip most often, and it's exactly the part that matters most for timing issues and race conditions.

2026-08-14 09:12:03.221  8421  8421 D LOGIN_FLOW: login started
2026-08-14 09:12:03.245  8421  8455 D LOGIN_FLOW: response received
2026-08-14 09:12:03.198  8421  8455 D LOGIN_FLOW: navigate to home

Look at the last line: its timestamp (09:12:03.198) is actually earlier than the second line (09:12:03.245), even though it's printed last. That's a sign two different threads are running in parallel, and navigate to home actually fired before the login response was fully received. Without paying attention to timestamps and thread IDs, this kind of thing is easy to miss — a developer just reads top-to-bottom and draws the wrong conclusion about execution order.

Writing Custom Logs That Actually Help

A log that just says "entered this function" doesn't help much. A useful log includes values, not just a position marker:

// Not very useful
Log.d("PAGINATION", "loadMore called")

// Much more useful
Log.d("PAGINATION", "loadMore: currentPage=$currentPage, nextPage=$nextPage, totalItem=${items.size}")
```

An example from my own work: on a digital signage project, the same app runs across dozens of different device types — different brands, chipsets, and Android versions. Bugs that show up often only appear on a specific device combination, and are nearly impossible to reproduce on a dev device. The fix was adding a device identifier (model, OS version) to every critical log, so that once logs came back from the field, I could immediately spot the pattern: was this issue tied to one chipset, one Android version, or was it happening across the board.

Common Logcat Mistakes

  • Forgetting to strip verbose logs from release builds — beyond the security risk of leaking sensitive data, it also drags down performance due to excessive logging I/O.
  • Inconsistent tags — one file uses the class name as a tag, another uses some random string, making filtering nearly impossible.
  • Only logging on error, never on the normal path — for race conditions especially, logs from the "successful" path are often the key to spotting the wrong execution order.

A carefully read Logcat is often enough on its own to answer most of the questions under the Evidence step from the 9-step framework covered earlier. Next up: another equally important source of evidence — reading stack traces, specifically when the app actually crashes.