adb-logcat
View Android system and app logs
TLDR
Display system logs
Display lines that match a reg[e]x
Display logs for a tag in a specific mode ([V]erbose, [D]ebug, [I]nfo, [W]arning, [E]rror, [F]atal, [S]ilent), filtering other tags
Display logs for React Native applications in [V]erbose mode [S]ilencing other tags
Display logs for all tags with priority level [W]arning and higher
Display logs for a specific PID
Display logs for the process of a specific package
Color the log (usually use with filters)
SYNOPSIS
adb logcat [options] [filter-spec ...]
PARAMETERS
-s
Silent mode. Only print log messages for selected tags.
-f <filename>
Output to file. Write log messages to the specified file.
-r <kbytes>
Rotate log file. Rotate the log file every <kbytes> of output (requires -f).
-n <count>
Max rotated files. Set the maximum number of rotated log files (requires -f and -r).
-v <format>
Output format. Set the output format for log messages (e.g., brief, long, threadtime, color). Common formats include: brief, long, process, raw, tag, thread, threadtime, time, color, epoch, monotonic, UTC, year.
-c
Clear buffer. Clear (flush) the entire log buffer and exit.
-C <count>
Clear and dump last N. Clear the log buffer and then dump the last <count> entries.
-b <buffer>
Select buffer. Load an alternative log buffer (e.g., main, system, radio, events, crash, kernel, default, all).
-D
Dump and exit. Print the buffer contents to the screen and exit.
-P <pid>, --pid=<pid>
Filter by PID. Select logs only from the specified process ID.
-S
Dump latest. Print only the latest event to the screen and exit.
-t <time_format>
Time format. Set the time format for log output (e.g., time, threadtime, UTC, epoch, monotonic).
-T <count>
Dump last N lines. Dump the most recent <count> lines from the buffer and exit.
-G <size>
Set buffer size. Set the log buffer size to <size>KB. Requires root or shell access.
--tag=<tag>
Filter by tag. Selects logs only from the specified tag.
<filter-spec>
Log filtering. Filters log output based on tag:priority pairs. Example: ActivityManager:I *:S (info for ActivityManager, silent for all others). Priority levels: V (Verbose), D (Debug), I (Info), W (Warn), E (Error), F (Fatal), S (Silent/off).
DESCRIPTION
adb logcat is a command-line tool that displays system messages (logs) from an Android device or emulator.
These logs are generated by various components of the Android system, including the kernel, services, applications, and the Android runtime. It's an essential tool for developers and testers to debug applications, understand system behavior, and diagnose issues.
logcat allows for real-time viewing of logs as they occur, as well as filtering logs based on various criteria like tag, priority, process ID (PID), or message content. The logs are organized into several circular buffers, and logcat can access them, clear them, or display specific portions.
It's part of the Android Debug Bridge (ADB) suite, which provides a versatile interface for communicating with Android devices. This command is crucial for understanding the internal workings of an Android application or system, helping to identify errors, warnings, and informational messages during development and troubleshooting.
CAVEATS
Log buffer size can be limited, leading to older logs being overwritten.
adb logcat can generate a large volume of data, making it hard to find relevant information without proper filtering.
Accessing certain log buffers or setting buffer size might require root privileges on the device.
Log formats can vary slightly across Android versions.
Running logcat on a heavily used device can impact performance due to constant I/O.
LOG BUFFERS
Android organizes logs into multiple circular buffers. You can select a specific buffer using the -b option:
main: Default log buffer for application-related messages.
system: Log buffer for system-component messages.
radio: Log buffer for radio/telephony related messages.
events: Log buffer for system events.
crash: Log buffer for crash dumps.
kernel: Log buffer for kernel messages.
default: Combines main, system, and crash buffers.
all: Combines all available buffers.
LOG PRIORITIES
Logcat uses priority levels to categorize log messages. When filtering, a higher priority level will also include all messages of even higher priority. Priorities from lowest to highest are:
V (Verbose): Show everything (lowest priority).
D (Debug): Debug-level messages.
I (Info): Informational messages.
W (Warn): Warnings.
E (Error): Errors.
F (Fatal): Fatal errors (highest priority).
S (Silent/off): Turn off all log messages for a tag.
HISTORY
adb logcat has been an integral part of the Android SDK and platform tools since the early days of Android development. It evolved alongside the Android operating system, with new features and log buffers being added to support new system components (e.g., events buffer for system events, crash for crash dumps). Its functionality has remained consistent as a primary tool for debugging and system analysis on Android devices.
SEE ALSO
adb(1), dmesg(1), journalctl(1), strace(1)