161

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
  • 12,226
  • 19
  • 85
  • 163
Tyrick
  • 2,294
  • 3
  • 20
  • 31

7 Answers7

201

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
  • 12,226
  • 19
  • 85
  • 163
Brandon S. Lee
  • 2,034
  • 1
  • 11
  • 4
165

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
  • 12,226
  • 19
  • 85
  • 163
RogueBaneling
  • 3,931
  • 4
  • 20
  • 33
  • 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.` – bigp Nov 29 '16 at 23:25
  • 10
    My personal favorite is `Log.wtf` (What a Terrible Failure) :D – Arthur Feb 21 '17 at 14:16
  • 6
    Jeez what a palaver! From someone coming from IOS developing this is really arcane in comparison. Just saying :-) – PhilipS Feb 02 '18 at 13:35
  • Does not work: `error: cannot find symbol variable log.` – Black Jan 21 '19 at 13:31
  • 3
    @PhilipS I agree. Android Studio and Android development is a pain and looks like an unproductive, horrible nightmare. Sad and frustrated. – monkSinha Mar 22 '19 at 03:35
  • To view this log, go to `Run` tab in bottom left of Android Studio. – Mohammad Zaid Pathan Jun 09 '20 at 18:47
23

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
  • 2,133
  • 1
  • 17
  • 29
Derek Soike
  • 8,670
  • 1
  • 64
  • 67
  • This should be the selected answer. – bah Jan 21 '18 at 17:21
  • 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
  • 2
    How to open the Android Monitor? – Black Jan 21 '19 at 13:34
6

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

See detailed answer with screenshot here.

Josh Correia
  • 2,133
  • 1
  • 17
  • 29
Shailendra Madda
  • 16,925
  • 14
  • 71
  • 115
0

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
  • 12,838
  • 4
  • 69
  • 82
0

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
  • 4,359
  • 1
  • 13
  • 32
0

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
  • 2,133
  • 1
  • 17
  • 29