With adb, how do you get logs off a misbehaving Android device and narrow logcat to your own tags and priorities?
answer
- pick the device before anything else
- tag and minimum priority pairs
- silence every tag you did not name
- three buffers are read by default
- a bug report for the whole picture
basics
~20 sList devices with adb devices, target one with -s, then run adb logcat with tag:priority filters ending in *:S so only your tags print; read the crash buffer for stack traces and take adb bugreport for a full capture.
solid answer
~40 sFirst make sure adb sees the phone: USB debugging on, the RSA key prompt accepted, and `adb devices -l` showing it in the `device` state. With several devices attached, pick one with `adb -s <serial>` or `ANDROID_SERIAL`, or adb fails with "more than one device/emulator". Then filter: `adb logcat CheckoutFlow:D AuthRepository:I *:S` prints those tags at or above their priority and silences everything else, while `adb logcat *:W` shows warnings and errors from every tag. By default logcat reads the `main`, `system` and `crash` buffers in `threadtime` format; `-b` picks others. Because the buffers are circular, capture early, and when you need everything at once run `adb bugreport` and hand over the file it writes.
code
console · 7 lines$ adb devices -l
List of devices attached
emulator-5554 device product:sdk_gphone64_x86_64 model:sdk_gphone64_x86_64
0a388e93 device usb:1-1 product:qa_phone model:QA_Phone
$ adb -s 0a388e93 logcat "CheckoutFlow:D AuthRepository:I *:S"
$ adb -s 0a388e93 logcat -b crash
$ adb -s 0a388e93 bugreportgo deeper
Recall the order: confirm the device with adb devices, target it, then filter with tag:priority pairs closed by *:S. Know the priority letters from V to S.
Explain why a tag pair alone filters nothing, which buffers logcat reads by default and why a circular buffer means you capture early.
Show how you get evidence from a tester you cannot sit beside: wireless pairing, a bug report instead of a live stream, and logs a release build may have stripped.
Frame logging as a field-diagnosis pipeline: what testers must capture by default, when a bug report replaces a live stream, and which tags the team commits to.
## Reaching the right device **adb** (Android Debug Bridge) is three programs: a **client** you type commands into, a **server** on your machine that listens on TCP port 5037, and the **adbd daemon** on the device. Before any log reaches you, the server has to hold a connection to the phone: - **USB debugging** must be switched on under Developer options, which are hidden until you enable them. - On Android 4.2.2 and higher the phone shows an **RSA key prompt**; until the tester unlocks the phone and accepts it, adb cannot run commands there. - `adb devices -l` lists every connection with its **serial** (`emulator-5554`, a hardware serial, or `ip:port` for wireless) and its **state**: `offline`, `device` or `no device`. The `device` state only means adb is connected. The system may still be booting. With more than one device attached, a command aimed at a device needs a target or adb stops with `adb: more than one device/emulator`: 1. `-s <serial>` names one device and overrides `ANDROID_SERIAL`. 2. `ANDROID_SERIAL` sets the serial once for a whole script. 3. `-d` picks the only hardware device and `-e` the only emulator. Each one fails when there are two of that kind. ## How logcat filtering works `adb logcat` is shorthand for `adb shell logcat`: the **logcat** tool runs on the device and reads the logs that the system process `logd` keeps. Every entry has a **tag** (a short string naming its source) and a **priority**, from lowest to highest `V` (verbose), `D`, `I`, `W`, `E`, `F` (fatal) and `S` (silent, which prints nothing). A filter expression is a list of `tag:priority` pairs. Each pair prints that tag at or above the priority given. On its own, a pair narrows nothing, because tags you did not name still print. The final `*:S` sets every other tag to silent, so the pairs before it become an **allowlist**: | Command | What prints | |---|---| | `adb logcat CheckoutFlow:D *:S` | only `CheckoutFlow`, Debug and above | | `adb logcat ActivityManager:I CheckoutFlow:D *:S` | two tags, each at its own floor | | `adb logcat *:W` | warnings, errors and fatals from every tag | | `adb logcat CheckoutFlow:D` | `CheckoutFlow` plus every other tag, so it filters nothing useful | Some shells expand `*`, so quote the whole expression: `adb logcat "CheckoutFlow:D *:S"`. ## Buffers and formats `logd` keeps several **circular buffers**. Old entries are overwritten as new ones arrive, so a freeze from an hour ago may already be gone: - `main`: most app logs. `system`: messages from the OS. `crash`: crash logs. - With no `-b` option, logcat reads `main`, `system` and `crash`, the set that `-b default` names. - `-b radio` and `-b events` read telephony and binary system-event logs. `-b all` reads every buffer, and you can repeat `-b` or give it a comma-separated list. `-v` picks one output format. `threadtime` is the default and shows the date, time, priority, tag, PID and TID. `brief`, `tag`, `time`, `raw` and `long` are among the others. Modifiers such as `color`, `UTC` or `year` can be added alongside it. ## Capturing everything: bug reports A filtered stream is the right tool while you watch a bug happen. When a tester is reporting a problem after the fact, ask for a **bug report**: `adb bugreport` on your machine, or **Take bug report** in Developer options on the phone. You get one file that bundles the device's logs and diagnostic state, ANR traces included. A retail phone gives you no root access, so this is how you get ANR traces off it. ## Wireless when there is no cable From Android 11 (API level 30), **Wireless debugging** pairs a phone without USB: choose *Pair using pairing code* on the device, run `adb pair <ip>:<port>` and type the code. You pair once. Android 17 together with adb 37.0.0 adds **adb Wi-Fi 2.0**, where a paired device reconnects on its own when it joins a trusted wireless debugging network. That discovery runs over mDNS, which `adb server-status` reports. On Android 10 and lower you still need USB once: run `adb tcpip 5555`, unplug, then `adb connect <ip>:5555`. ## Common mistakes - Filtering with a tag pair and no `*:S`, then blaming logcat for the noise. - Reading the stream long after the event, when the circular buffer has already wrapped. - Expecting `Log.d` lines from a release build that strips them at compile time.
- The tester's phone is not on a cable. How do you attach adb over Wi-Fi?On Android 11 (API 30) or higher, enable Wireless debugging, choose Pair using pairing code, then run `adb pair <ip>:<port>` and enter the code. The pairing lasts until the tester forgets it or revokes the authorizations. On Android 17 with adb 37.0.0, adb Wi-Fi 2.0 reconnects a paired device automatically on a trusted network. On Android 10 and lower you need USB once: `adb tcpip 5555`, unplug, then `adb connect <ip>:5555`.
- Your filter is correct but your `Log.d` lines never appear from the release build. Why?Logs pass through several filters before logcat shows them. The display filter is only the last one. A release build can be configured to strip `Log.d` calls at compile time, so those lines no longer exist in the binary. Check what the build removes before you question the filter.
- How do you avoid passing `-s` to every command in a long script?Export `ANDROID_SERIAL` with the device's serial from `adb devices`. Every adb command in that shell then targets it. A `-s` on a single command still overrides the variable, which is handy when one step has to reach a second device.
- adb logcat MyApp:D on its own shows only MyApp's messages
- Once adb devices lists the phone as device, it has finished booting
- You need -b all before any crash stack trace shows up
- With several devices attached, adb just uses the first one
- logcat keeps every message since boot, so you can read it later
Assumes Android 17 (API 37) with adb 37.0.0: adb Wi-Fi 2.0 auto-reconnect needs both, while pairing-code wireless debugging works from Android 11 (API 30).