203

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.

nbro
  • 15,395
  • 32
  • 113
  • 196
Tyrick
  • 2,776
  • 3
  • 23
  • 33

8 Answers8

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.

nbro
  • 15,395
  • 32
  • 113
  • 196
Brandon S. Lee
  • 2,334
  • 1
  • 13
  • 4
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".

nbro
  • 15,395
  • 32
  • 113
  • 196
RogueBaneling
  • 4,331
  • 4
  • 22
  • 33
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

Josh Correia
  • 3,807
  • 3
  • 33
  • 50
Derek Soike
  • 11,238
  • 3
  • 79
  • 74
  • 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 '18 at 03:41
  • 3
    How to open the Android Monitor? – Black Jan 21 '19 at 13:34
17

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

See detailed answer with screenshot here.

Josh Correia
  • 3,807
  • 3
  • 33
  • 50
Shailendra Madda
  • 20,649
  • 15
  • 100
  • 138
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.

Josh Correia
  • 3,807
  • 3
  • 33
  • 50
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

Samiya Khan
  • 241
  • 3
  • 4
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.

Zon
  • 18,610
  • 7
  • 91
  • 99
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

Jay Mungara
  • 6,663
  • 2
  • 27
  • 49