Logcat is an Android SDK tool for viewing system messages and application logs in real time, available via ADB or the built-in Android Studio console. According to Android Developers, Logcat collects messages from all system processes, filters them by priority levels and tags, and allows developers to diagnose errors, track code execution, and analyze performance. Logcat is the primary source of information when debugging Android applications.
Key Takeaways
Logcat is an Android system buffer where all processes (including the Linux kernel, system_server, and apps) write messages in a specific format. The logcat tool, included in the Android SDK, reads this buffer and displays messages in real time. Starting with Android 4.1 (API 16), Logcat access is restricted: apps can only read their own logs, and system logs are accessible via ADB with debug access.
Each Logcat message contains five fields: date and time, PID (process identifier), TID (thread identifier), log level, and tag. The format is fixed and identical across all Android versions. This allows using grep, awk, and sed utilities for log filtering in CI/CD pipelines without IDE dependency.
Logs are stored in a fixed-size ring buffer: 256 KB for main, 256 KB for system, and 256 KB for events (Android 5+). When the buffer overflows, old messages are deleted. Developers can change the buffer size via the PROP logcat.size property or in the device’s developer options.
Six levels of logging determine message importance. Android uses standard levels similar to other platforms but with its own constant names in the Log class. Choosing the right level helps efficiently filter logs and avoid drowning out critical messages with secondary ones.
| Level | Constant | Purpose | Shown by Default |
|---|---|---|---|
| VERBOSE | Log.v | Maximum detailed debugging information | No |
| DEBUG | Log.d | Debug messages for developers | No |
| INFO | Log.i | Informational messages about app operation | Yes |
| WARN | Log.w | Warnings about potential issues | Yes |
| ERROR | Log.e | Critical errors and exceptions | Yes |
| ASSERT | Log.wtf | Errors that should never happen | Yes |
Tag — a string of up to 23 characters that identifies the message source. It is recommended to use the class or module name as the tag: MainActivity, AuthManager, NetworkModule. This allows filtering logs by a specific application component. For consistency within a team, you can create tag constants in a separate file or use the Timber library, which automatically inserts the tag based on the class name.
When an unhandled exception occurs, Android automatically writes the full stack trace to Logcat, indicating the class, method, code line, and call chain. A crash log contains the exception type (NullPointerException, RuntimeException), message, and call sequence from the crash point to the app’s entry point. For analyzing crash logs from user devices, Firebase Crashlytics is used, which synchronizes the stack trace with the obfuscation map (mapping.txt for Android).
Android Studio provides a graphical Logcat interface accessible via View → Tool Windows → Logcat (Alt + 6). The Logcat window updates in real time, shows all messages from the connected device, and allows configuring flexible filters to isolate the desired information from the general stream.
The Log Level dropdown filters messages by minimum level: select WARN to see only warnings and errors, hiding VERBOSE, DEBUG, and INFO. The Search field allows searching by message text or tag — regex is supported, which is convenient for finding messages by pattern.
Saved Filters — a powerful Logcat feature in Android Studio. You can create a filter that shows only messages with your app’s tag (tag:MyApp) and level WARN+. Filters persist between sessions and are available from the dropdown list. For projects with multiple modules, create a separate filter for each module.
# Example of an expression for filtering application logs
tag:"MyApp" level:WARN # Only WARN+ for MyApp
package:"com.mycompany" # All package logs
-tag:"okhttp" # Exclude OkHttp logs
Logcat logs can be exported to a text file via the Save to File icon. This is useful for attaching to Jira tickets or analyzing long sessions. The exported log can be opened in any text editor and grep can be applied to search for patterns. For formatted viewing, use the logcat-color utility.
ADB logcat is the console version of Logcat, accessible via Android Debug Bridge. Its main advantage is the ability to run on CI servers, in automation scripts, and on devices without Android Studio. ADB logcat supports all the same filters as the GUI, but with command-line flexibility.
The adb logcat command without arguments outputs the entire buffer in real time. Use Ctrl+C to stop. The -c flag clears the buffer before starting recording — convenient when you need to isolate the current test’s logs from previous messages. The -b flag selects the buffer type: main, system, events, crash (Android 12+).
# Clear the buffer and start logging with the MyApp tag
adb logcat -c
adb logcat MyApp:D *:S
# Save logs to file
adb logcat -d > logcat_dump.txt
# Filter by process PID
adb logcat --pid=12345
Combining ADB with Unix utilities provides maximum flexibility. For example, the filter "*:S TAG:D" shows only messages with the TAG tag at DEBUG level and above, hiding everything else. To view only exceptions, use grep -i exception. To analyze error frequency, apply sort | uniq -c on the tag column.
On CI servers, Logcat is used to collect diagnostics during UI test runs. A typical pipeline: clear the buffer before running tests, save the log dump as a build artifact after test execution. If a test fails, the logs can determine whether the failure was caused by ANR, unhandled exception, or network timeout.
The android.util.Log class is the built-in API for writing messages to Logcat. Log.v, Log.d, Log.i, Log.w, Log.e, and Log.wtf accept a tag (string) and a message (string) or a message + Throwable. For formatting messages, use String.format or Kotlin String templates — avoid string concatenation, which creates unnecessary objects in the heap.
Timber is a popular library by Jake Wharton that addresses the shortcomings of the built-in Log API. Timber automatically inserts the tag based on the class name that called logging and does not require passing a tag in every call. Timber also supports conditional logging: in Release builds, Timber.v and Timber.d calls can be disabled with a single line in Application.onCreate.
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
// Built-in Log API
Log.d("MainActivity", "onCreate called")
// Timber — automatic tag by class name
Timber.d("onCreate called")
}
private fun loadData() {
try {
val result = fetchFromNetwork()
Timber.i("Data loaded: $result")
} catch (e: IOException) {
Timber.e(e, "Failed to load data")
}
}
}
In Release builds, it is recommended to disable VERBOSE and DEBUG logs to reduce Logcat buffer load and prevent sensitive information leaks. Timber solves this with PlantingTree: in the Debug flavor, DebugTree is planted (logs everything), in Release — CrashReportingTree (logs only ERROR via Crashlytics). The built-in Log API does not support conditional logging — developers need to wrap each call with if (BuildConfig.DEBUG).
Frequently Asked Questions
Use the adb logcat -c command before running a test. Alternatively, in Android Studio, click the Clear Logcat button (trash icon) in the Logcat window. Clearing does not affect system buffers of other processes, only the current connection.
Run adb logcat -G 2M to increase the buffer to 2 MB. The maximum size depends on the device: on Android 10+, up to 16 MB is available. The change persists until the device is rebooted. For permanent configuration, use build.prop in the device tree.
Possible reasons: the app is running in Release mode (Timber.v/d logs disabled), the Logcat filter is hiding the required level, or you are connected to the wrong device. Also check that you have selected your app’s process in Android Studio, not system_process.
Find the line with FATAL EXCEPTION, followed by the full stack trace. The first line contains the exception type and message, subsequent lines contain the call chain with file and code line information. Use grep "FATAL EXCEPTION" for quick searching among all logs.
ANR (Application Not Responding) is a situation where the main thread (UI thread) is blocked for more than 5 seconds. In Logcat, ANR appears as a message with the tag ActivityManager and text "ANR in ..." with an attached stack trace of all threads. Use the filter tag:ActivityManager level:ERROR.
Summary
We will develop a mobile application turnkey
IT Sectr creates iOS and Android applications for startups and businesses since 2017. We will advise you and propose the best solution.
Read also