9

In Eclipse, how can I write a debug statement to a console window? I tried:

System.out.print(urls);

System.out.println(urls);       

Log.d("tag", urls);

But I don't see the values being displayed anywhere.

Thanks.

jtbandes
  • 115,675
  • 35
  • 233
  • 266
drbob
  • 131
  • 1
  • 2
  • 3
  • I'm having the same problem and it's very frustrating. Everything is enabled properly, but the output is not going to the console. Did you find a solution? Are you running under Win7 by any chance? I am wondering if it is something specific to Win7. – RickNotFred Mar 04 '10 at 20:55
  • Where are your streamouts set? I ran to this same problem because it was streaming out to a file without me knowing and then I had to System.setout() get it streaming to the right place. – maestroanth Apr 18 '14 at 00:25

8 Answers8

6

Create a console and write to it. When a console is created, you give it a name. That way your console output can be kept separate from other plugin's console output. See this article for details.

http://wiki.eclipse.org/FAQ_How_do_I_write_to_the_console_from_a_plug-in%3F

aerobiotic
  • 381
  • 2
  • 5
  • The link didn't work for me when clicking or copy-pasting it (I blame that `%3F` on the end). The page does exist though, you might just have to Google for it: https://www.google.com.au/webhp?q=FAQ%20How%20do%20I%20write%20to%20the%20console%20from%20a%20plug-in%3F#q=FAQ+How+do+I+write+to+the+console+from+a+plug-in%3F – Tom Saleeba Nov 07 '14 at 04:06
  • I found correct link which uses https https://wiki.eclipse.org/FAQ_How_do_I_write_to_the_console_from_a_plug-in_%3F – ashah Jan 11 '17 at 05:54
4

Are you sure you have the console window in eclipse setup to display output? On the menu bar in eclipse, go to Window->Show View->Console. When you run the program, that console window should be where your System.out.print(ln) output is displayed.

dcp
  • 54,410
  • 22
  • 144
  • 164
3

My output goes to the LogCat tab, not the Console.

austin
  • 998
  • 2
  • 12
  • 22
3

If you are running some kind of client-server application, you may actually have multiple consoles. If you see a console, there should be a little arrow icon next to it. Use that to dropdown a list of all the various consoles, and pick the appropriate one.

Greg Charles
  • 1,880
  • 4
  • 20
  • 39
1

If you are running any class having main method and want to print logs on eclipse console, then create a file "log4j.properties" in src/main/resources

If you want to print log in your test classes then put this file in src/test/resources.

log4j.properties

log4j.rootLogger=INFO, DEBUG, WARN, ERROR, stdout

log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%5p [%C:%L] [%t] - %m%n

log4j.logger.backtype.storm=DEBUG
log4j.logger.clojure.tools=DEBUG
shashaDenovo
  • 1,638
  • 21
  • 21
1

There is a simple way to switch between client and server outputs in eclipse. Please see the screenshot which shows an option to toggle between the console outputs.

Eclipse screenshot to show console option

spatel
  • 11
  • 2
0

try this , it will output in console tab

System.out.print("Hello World ..... !");       
// Redirect the stdout and stderr to the LogPanel
SystemLogger out = new SystemLogger(System.out, Level.INFO);
SystemLogger err = new SystemLogger(System.err, Level.ERROR);
System.setOut(out);
System.setErr(err);
user889030
  • 4,353
  • 3
  • 48
  • 51
0

I assume your code is in Java? If you want to use a logger that will print out to your console similarly to "system.out.println();", add java.util.logging to your eclipse project. import java.util.logging.Logger;

Then inside each class where you want output to your console, add private static final Logger LOG = Logger.getLogger(<your_class_name>.class.getName()); replacing with your class name.

And where you want console output, put a line in that part of your class like LOG.info("code got to this point!"); similarly to how you would use system.out.println();

I only use the logger instead of system.out.println(); statements because the logging seems more professional. And frankly the logger is less key strokes to write log.info than system.out.println, which saves time.

This article is where I learned the logging info: https://examples.javacodegeeks.com/core-java/util/logging/java-util-logging-example/

Sammy Cakes
  • 162
  • 2
  • 11