The Logcat window in Android Studio is an essential tool for debugging your app by displaying logs from your device in real-time. With Logcat, you can track messages added to your app using the Log class, system messages, and more. When an exception occurs, Logcat shows a message followed by the associated stack trace with links to the line of code.

Getting Started with Logcat

To view log messages for your app, follow these steps:

  • Build and run your app on a physical device or emulator.
  • Select View > Tool Windows > Logcat from the menu bar.

By default, Logcat scrolls to the end. To turn this feature off, click in the Logcat view or use your mouse wheel to scroll up. You can also use the toolbar to clear, pause, or restart Logcat.

Reading Logs

Each log entry has a date, timestamp, process and thread ID, tag, package name, priority, and message associated with it. Different tags have unique colors that help identify the type of log. The standard log view displays each log's information by default, but you can use the Soft-Wrap option to wrap long messages.

Configuring the Log View

You can customize the log view to suit your needs. By default, message lines are not wrapped in the log view, but you can enable this feature using the toolbar. You can also switch to Compact view, which has less default display information, or modify the views to show or hide specific fields.

Customizing Colors

To change the color scheme of your log view, navigate to Android Studio > Settings > Editor > Color Scheme and select Android Logcat. You can also customize the color scheme of your filter by selecting Logcat Filter.

Additional Configuration Options

For more configuration options, navigate to Android Studio > Settings > Tools > Logcat. From here, you can choose the Logcat cycle buffer size, default filter for new Logcat windows, and whether you want to add filters from history to autocomplete.

Using Logcat in Multiple Windows

You can create multiple Logcat tabs by clicking New Tab. Right-clicking a tab lets you rename and rearrange it. You can also split the view within a tab to compare between two sets of logs or keep a particular line visible using the toolbar.

Querying Logs Using Key-Value Search

In Android Studio, you can generate key-value searches right from the main query field. This query system provides accuracy by excluding logs based on key-values. You can use regular expressions for queries and even get suggestions by pressing Ctrl + Space in the query field.

Some examples of keys you can use in your query include:

  • tag: Matches against thetag field of the log entry.
  • package: Matches against the package name of the logging app.
  • process: Matches against the process name of the logging app.
  • message: Matches against the message part of the log entry.
  • level: Matches the specified or higher severe log level (e.g., DEBUG).
  • age: Matches if the entry timestamp is recent. Values are specified as a number followed by a letter specifying the time unit.

Negation and Regular Expressions

The following fields support negation and regular expression matching:

  • tag
  • package
  • message
  • line

You can use negation by prepending a - to the field name, or regular expressions by appending a ~. You can also combine negation and regular expression modifiers.

Logical Operators and Parentheses

The query language supports logical operators (AND and OR) expressed by & and |, as well as parentheses. For example:

(tag:foo | level:ERROR) & package:mine

Note that normal operator precedence is enforced, so the following:

tag:foo | level:ERROR & package:mine

Is evaluated as:

(tag:foo | (level:ERROR & package:mine))

Implicit Logical Operators

If logical operators are not applied, the query language automatically evaluates multiple non-negated key-value filter terms with the same key as an OR, and everything else with an AND.