Appearance
adb logcat: read, filter and save Android logs
In short: adb logcat shows an Android phone's system log on your computer, including messages and crash reports from apps. Run adb logcat to follow it live, adb logcat -d to print what is there and stop, and adb logcat -c to clear it. Filter by priority with *:E, by app with --pid, and save it with adb logcat -d > log.txt.
Logcat is where Android and every app write what they are doing, so it is the first place to look when an app misbehaves on a phone. adb logcat prints those log messages in your terminal; Android Studio's Logcat window (View, Tool Windows, Logcat) shows the same output with filters, if you have the SDK installed.
Syntax
bash
adb logcat [options] [tag:priority ...]| Option | What it does |
|---|---|
-d | Prints the log so far and stops, instead of following it |
-c | Clears the log |
-b crash | Shows only the crash buffer; -b all shows every buffer |
--pid=1234 | Shows only one process's messages |
-t 200 | Prints only the last 200 lines |
-v color | Colours each line by priority; the default format is threadtime |
-e regex | Shows only lines that match a regular expression |
Options depend on the phone's Android version; adb logcat --help lists the ones a phone has.
Read a log line
The default output format, threadtime, gives every line the same fields:
text
11-22 10:41:07.512 4321 4350 E AndroidRuntime: FATAL EXCEPTION: main| Field | Here | Meaning |
|---|---|---|
| Date and time | 11-22 10:41:07.512 | When the message was written, on the phone's clock |
| PID | 4321 | The process that wrote it, one per running app |
| TID | 4350 | The thread inside that process |
| Priority | E | The level, from V verbose to F fatal |
| Tag | AndroidRuntime | Who wrote it: an app's own tag, or a system component |
| Message | FATAL EXCEPTION: main | The text itself |
Change the format with -v: brief, process, tag, thread, raw, time, threadtime and long are the formats, and modifiers such as color, year, UTC and epoch add to them, for example adb logcat -v time,color.
Filter by priority and tag
Priorities run from lowest to highest: V verbose, D debug, I info, W warning, E error, F fatal, and S silent, which hides everything. A filter is tag:priority; * means every tag.
bash
# Errors and worse, from every tag (quote * so the shell leaves it alone)
adb logcat '*:E'
# Your app's tag at debug and above, ActivityManager at info, nothing else
adb logcat ActivityManager:I MyApp:D '*:S'
# Only one app, while it is running
adb logcat --pid=$(adb shell pidof -s com.example.app)The ADB command builder writes these filters for you: pick Read the log, name your tags, an app, a regular expression or a buffer, and copy the command for bash or PowerShell.
Save the log to a file
bash
adb logcat -d > log.txtpowershell
adb logcat -d | Out-File -Encoding utf8 log.txtPlain > in Windows PowerShell 5.1 writes UTF-16 text, which some editors and tools read badly; Out-File -Encoding utf8 writes ordinary UTF-8.
Log buffers: where the log is kept
The phone keeps its log in memory, in several ring buffers of fixed size, so the oldest lines are dropped as new ones arrive and the log starts empty after a restart. -b chooses the buffers to read:
| Buffer | What it holds |
|---|---|
main | Most app and system log messages |
system | Messages from Android's system services |
crash | Crash reports |
events | Binary system events, printed as text |
radio | Mobile network and telephony messages |
default | main, system and crash together; what plain adb logcat reads |
all | Every buffer |
Read several at once with a comma (adb logcat -b main,radio). adb logcat -g prints each buffer's size and adb logcat -G 16M makes the buffers bigger, so a crash stays in the log longer. Reading the log needs no root, but an app on the phone may read only its own lines unless it is granted READ_LOGS.
Investigate a crash: find out why an app crashed
- Clear the log with
adb logcat -c, then make the app crash again. - Run
adb logcat -b crash -dand look forFATAL EXCEPTION. The lines below it are the stack trace: the first line names the error, and the lines that mention your app's classes show where it happened. - If the app froze instead of closing, search the main log for
ANR infollowed by your app's package name. - For a full picture,
adb bugreport report.zipcollects the logs and much more in one file.
On many phones at once
When a test fails on some phones only, save each phone's log under its own name:
bash
for s in $(adb devices | awk 'NR>1 && $2=="device" {print $1}'); do
adb -s "$s" logcat -d > "log-${s//[:\/]/_}.txt"
donepowershell
adb devices | Select-Object -Skip 1 | ForEach-Object {
$serial, $state = $_ -split '\s+'
if ($state -eq 'device') { adb -s $serial logcat -d | Out-File -Encoding utf8 "log-$($serial -replace '[:\\/]', '_').txt" }
}In BenchFleet, each phone's page has its logcat next to the live screen, on every plan, so you can watch the log while you reproduce the problem by hand. Logcat, APKs and a shell on many phones shows that page, and Android app testing on real devices where the log fits in a test run.
Free for up to 3 phones, with no account. Pro adds workflows, schedules and AI for up to 25 phones from $16 a month + VAT (including 300 cloud phone minutes every month).
Common errors and fixes
| Problem | What it means | Fix |
|---|---|---|
- waiting for device - | adb sees no phone and waits for one | Connect the phone; see adb devices |
Nothing shows with --pid | The app was not running, so pidof found no process | Open the app first, then run the command |
| The crash is no longer in the log | The log buffer is full and old lines were dropped | Read the log right after the crash, or make the buffer bigger with adb logcat -G 16M |
adb: more than one device/emulator | Several phones are connected | Choose one with -s and its serial number |
Related
- adb shell: restart the app or change settings while you watch the log.
- adb install: put a fixed build on the phone.
- adb screenshot: capture what was on screen when it went wrong.
- ADB over Wi-Fi: keep reading the log while the phone is off the cable.
- Google's logcat command-line reference covers filter expressions, output formats and log buffers.
- All ADB commands and the ADB command builder.
Questions
What is the adb command for logcat?
adb logcat. On its own it follows the log live until you press Ctrl+C; adb logcat -d prints the log so far and stops, which is what you want when saving it to a file.
How do I filter logcat by app?
Give logcat the app's process ID, which pidof finds while the app is running, for example adb logcat --pid=$(adb shell pidof -s com.example.app). Filtering by your app's own log tags, such as MyApp:D *:S, also works.
How do I save logcat to a file?
In bash or zsh, run adb logcat -d > log.txt. In PowerShell, run adb logcat -d | Out-File -Encoding utf8 log.txt, so the file is plain UTF-8 text.
How do I clear logcat?
Run adb logcat -c. It empties the log buffers, so the next adb logcat shows only new messages, which makes a fresh test run easier to read.
How do I find out why an app crashed?
Run adb logcat -b crash -d right after the crash and look for FATAL EXCEPTION; the lines after it are the stack trace that names the error and where it happened. For a frozen app, look for ANR in the main log, or collect everything with adb bugreport.
Can I see the log in Android Studio instead of a terminal?
Yes. Android Studio's Logcat window (View, Tool Windows, Logcat) shows the same log messages from a connected phone or emulator, with filters by app, tag and level. adb logcat is the command line tool behind the same output, handy when Android Studio is not installed.
Can I read the log on the phone without a computer?
Log reader apps can, but Android lets them read other apps' logs only after you grant them the READ_LOGS permission once, with adb shell pm grant and the app's package name.
Start with the Free plan
Free for up to 3 phones, with no account. Pro adds workflows, schedules and AI for up to 25 phones from $16 a month + VAT (including 300 cloud phone minutes every month).
- A Free plan with no time limit and no account
- Starts in Local mode, with no telemetry or analytics in the app