Skip to content

Most visited

Recently visited


Write and View Logs with Logcat

Android Monitor includes a logcat Monitor that displays debug messages. The logcat Monitor displays system messages, such as when a garbage collection occurs, as well as messages that you can add to your app using the Log class. It displays messages in real time and also keeps a history so you can view older messages.

To display just the information of interest, you can create filters, modify how much information is displayed in messages, set priority levels, display messages produced by app code only, and search the log. By default, the logcat Monitor shows the log output related to the most recently run app only.

When an app throws an exception, the logcat Monitor shows a message followed by the associated stack trace containing links to the code. This feature can help you fix errors and improve app operation.

As of Android Studio 2.2, the Run window also displays log messages for the current running app. Note that you can configure the logcat Monitor display, but not the Run window.

logcat Message Format

Every Android log message has a tag and a priority associated with it. The tag of a system log message is a short string indicating the system component from which the message originates (for example, ActivityManager). A user-defined tag can be any string that you find helpful, such as the name of the current class (the recommended tag). You define it in a Log method call, for example:

Log.d(tag, message);

The priority is one of the following values:

The log message format is:

date time PID-TID/package priority/tag: message

For example, the following log message has a priority of V and a tag of AuthZen:

12-10 13:02:50.071 1901-4229/ V/AuthZen: Handling delegate intent.

PID stands for process identifier and TID is thread identifier; they can be the same if there’s only one thread.

Displaying a Running App in the logcat Monitor

To display the log messages for a particular app:

  1. Meet the prerequisites and dependencies.
  2. Open an app project.
  3. Run the app on a hardware device or emulator.
  4. Display Android Monitor.
  5. Click the logcat tab.
  6. By default, the logcat Monitor displays just the log messages for your app running on the device or emulator:

    To change this default, see Filtering logcat Messages.

  7. Optionally select a different device, emulator, or process.

Setting the Log Level

You can control how many messages appear in the logcat Monitor by setting the log level. You can display all messages, or just the messages indicating the most severe conditions.

Remember that the logcat Monitor continues to collect all messages regardless of the log level setting. The setting just determines what the logcat Monitor displays.

To set the log level:

Searching logcat Messages

To search the messages currently displayed in the logcat Monitor:

  1. Optionally select Regex if you want to use a regular expression search pattern.
  2. Type a character sequence in the search field Search icon.
  3. The logcat Monitor display changes accordingly.

  4. Press Enter to store the search string in the menu during this session.
  5. To repeat a search, choose it from the search menu. Select or deselect Regex as needed (the setting isn’t remembered).

Filtering logcat Messages

One way to reduce the log output to a manageable level is to restrict it by using a filter.

Note: The filter applies to your full logcat history, not just those messages currently displayed in the logcat Monitor. Make sure your other display options are set appropriately so you can see the filter output you want to examine.

To define and apply a filter:

  1. In the filter menu, select a filter option:
    • Show only selected application - Display the messages produced by the app code only (the default). The logcat Monitor filters the log messages using the PID of the active app.
    • No Filters - Apply no filters. The logcat Monitor displays all log messages from the device, regardless of which process you selected.
    • Edit Filter Configuration - Create or modify a custom filter. For example, you could create a filter to view log messages from two apps at the same time.

    After you define filters, you can also select them in the menu. To remove them from the menu, delete them.

  2. If you selected Edit Filter Configuration, create or modify a filter.
    1. Specify the filter parameters in the Create New Logcat Filter dialog:
      • Filter Name - Type the name of a filter you want to define, or select it in the left pane to modify an existing filter. The name can contain lowercase characters, underscores, and digits only.
      • Log Tag - Optionally specify a tag. For more information, see logcat Message Format.
      • Log Message - Optionally specify log message text. For more information, see logcat Message Format.
      • Package Name - Optionally specify a package name. For more information, see logcat Message Format.
      • PID - Optionally specify a process ID. For more information, see logcat Message Format.
      • Log Level - Optionally select a log level. For more information, see Setting the Log Level.
      • Regex - Select this option to use regular expression syntax for that parameter.
    2. Click + to add the filter definition to the left pane.
    3. To remove a filter, select it in the left pane and click -.

    4. When you’re finished, click OK. If you click Cancel, any filter additions or modifications are lost.
  3. Make sure you see the log messages you want to examine.
  4. If you don't think you see the log messages you want, try selecting No filters and searching for particular log messages.

Configuring the logcat Header Display

To customize the header display to show just the information you’re interested in:

For more information about message elements, see logcat Message Format.

Moving Up and Down the Stack Trace

When the app throws an exception, the message includes a stack trace of method calls. logcat Monitor lets you quickly locate stack traces in the log and view the associated code in the Code Editor. If needed (and possible), the decompiler derives source code that you can view.

To move up and down the stack trace, and view the associated code in the Code Editor:

Moving to the End of the Log

Clicking a particular message stops the display of messages.

To quickly move to the end of the log to see the real-time message flow:

Printing and Writing to a File

To preserve log information, you can send the log to a printer, write the log to a PDF file, or copy and paste the log into a text file.

To print the log or write it to a PDF file:

  1. Click Print Print icon.
  2. In the Android Studio Print dialog, optionally change print parameters, and then click Print.
  3. In the operating system Print dialog, optionally change print parameters, and then click Print.
  4. You can set the parameters to send the log to a printer or write it to a PDF file.

To copy the log to a text file:

  1. In the logcat Monitor, select and then copy log text.
  2. Press Control+A (Command+A) to select all.

  3. Open a text editor and paste the text into a file.

Clearing and Restarting the Log

To clear (flush) the entire log:

If there's a problem and the log is no longer progressing, you can restart the log:

Adding Log Messages to Your Code

The Log class allows you to create log messages that appear in the logcat Monitor. Generally, you should use the following log methods, listed in order from the highest to lowest priority (or, least to most verbose):

See the Log class description for a more complete list of options.

You should never compile verbose logs into your app, except during development. Debug logs are compiled in but stripped at runtime, while error, warning, and info logs are always kept.

For each log method, the first parameter should be a unique tag and the second parameter is the message. The tag of a system log message is a short string indicating the system component from which the message originates (for example, ActivityManager ). Your tag can be any string that you find helpful, such as the name of the current class.

A good convention is to declare a TAG constant in your class to use in the first parameter. For example, you might create an information log message as follows:

private static final String TAG = "MyActivity";
Log.i(TAG, "MyClass.getView() — get item number " + position);

Note: Tag names greater than 23 characters are truncated in the logcat output.

This site uses cookies to store your preferences for site-specific language and display options.

Get the latest Android developer news and tips that will help you find success on Google Play.

* Required Fields


Browse this site in ?

You requested a page in , but your language preference for this site is .

Would you like to change your language preference and browse this site in ? If you want to change your language preference later, use the language menu at the bottom of each page.

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.

Take a short survey?
Help us improve the Android developer experience.
(Sep 2017 survey)