204

I just downloaded Android Studio for Linux from: http://developer.android.com/sdk/installing/studio.html

I'm wondering how to print to the console?

Neither System.out.print(...) nor Log.e(...) from android.util.Log seem to work.

2

8 Answers 8

231

Run your application in debug mode by clicking on

enter image description here

in the upper menu of Android Studio.

In the bottom status bar, click 5: Debug button, next to the 4: Run button.

Now you should select the Logcat console.

In search box, you can type the tag of your message, and your message should appear, like in the following picture (where the tag is CREATION):

enter image description here

Check this article for more information.

0
202

Android has its own method of printing messages (called logs) to the console, known as the LogCat.

When you want to print something to the LogCat, you use a Log object, and specify the category of message.

The main options are:

  • DEBUG: Log.d
  • ERROR: Log.e
  • INFO: Log.i
  • VERBOSE: Log.v
  • WARN: Log.w

You print a message by using a Log statement in your code, like the following example:

Log.d("myTag", "This is my message");

Within Android Studio, you can search for log messages labelled myTag to easily find the message in the LogCat. You can also choose to filter logs by category, such as "Debug" or "Warn".

4
  • What could be causing the following error when trying to use Log? Could not get unknown property 'Log' for object of type com.android.build.gradle.internal.api.LibraryVariantImpl. Nov 29, 2016 at 23:25
  • 20
    My personal favorite is Log.wtf (What a Terrible Failure) :D
    – Arthur
    Feb 21, 2017 at 14:16
  • Does not work: error: cannot find symbol variable log.
    – Black
    Jan 21, 2019 at 13:31
  • To view this log, go to Run tab in bottom left of Android Studio. Jun 9, 2020 at 18:47
26

Android Studio 3.0 and earlier:

If the other solutions don't work, you can always see the output in the Android Monitor.


android studio screen shot


Make sure to set your filter to Show only selected application or create a custom filter.

enter image description here

2
  • My mistake was not properly setting the top 2 drop-down boxes in Android Monitor (having multiple emulators running I assumed the last running emulator and app would be auto selected - not so).
    – site
    Aug 31, 2018 at 3:41
  • 3
    How to open the Android Monitor?
    – Black
    Jan 21, 2019 at 13:34
17

You can see the println() statements in the Run window of Android Studio.

See detailed answer with screenshot here.

2

Be careful when using Logcat, it will truncate your message after ~4,076 bytes which can cause a lot of headache if you're printing out large amounts of data.

To get around this you have to write a function that will break it up into multiple parts like so.

2

In kotlin, you can use logcat to print in console.

Logcat is made of 2 parameters: one is Tag and second is string (that you want to print).

Their are mainly 5 types of Logcat

  1. Error Level: Something went seriously wrong

    Log.e(TAG, "ERROR")

  2. Warn Level: Less severe than an error but still neec be fixed

    Log.w(TAG, "WARN")

  3. Info Level: Used we need to provide information

    Log.i(TAG, "INFO")

  4. Debug Level: Information that may be useful when addressing an issue

    Log.d(TAG, "DEBUG")

  5. Verbose Level: Least specific log level

    Log.v(TAG, "VERBOSE")

Error log in red, warn log in blue and other three in black color.

Different Color of Logcat

1
  • 1
    Thank you, I am searching for the error log in Kotlin, and it is the same.
    – Imran Khan
    Mar 23 at 5:27
1

If your app is launched from device, not IDE, you can do later in menu: Run - Attach Debugger to Android Process.

This can be useful when debugging notifications on closed application.

1

I had solve the issue by revoking my USB debugging authorizations.

To Revoke,

Go to Device Settings > Enable Developer Options > Revoke USB debugging authorizations

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.