Reputation: 913
In Eclipse's console I can only see the tomcat server start logs, but then nothing else, none of the system.out.print() from my application are displayed, which makes it difficult to debug.
What settings can I change in Eclipse to get my system.out.print() out put back in the console?
Upvotes: 1
Views: 5631
Reputation: 1
You also might try to clean the project (Project -> Clean), it helped to me and System.out started to show in console again.
Upvotes: 0
Reputation: 1691
Ok, the best approach is always to use a logger and log4j is my preferred tool.
First configure the logger by creating a log4j.properties file. Here is a good example that matches your problem:
# Set root category priority to INFO and its only appender to CONSOLE.
log4j.rootCategory=INFO, CONSOLE, LOGFILE
# CONSOLE is set to be a ConsoleAppender using a PatternLayout.
log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
log4j.appender.CONSOLE.Threshold=INFO
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
log4j.appender.CONSOLE.layout.ConversionPattern=- %m%n
This configuration will send info and above messages to the console. Now how you want your log4j.properties to initialize and how you want to reference the the log4j jar libraries dependends upon how you deploy your application.
A good reference for configuration on stackoverflow is here: Where should I put the log4j.properties file?
A good reference on log4j usage is here:http://www.codejava.net/coding/how-to-configure-log4j-as-logging-mechanism-in-java
Note you can configure in multiple ways. It is your call. Now in your class file initialize the logger:
public class MyClass {
private static final Logger log = Logger.getLogger(MyClass.class);
....
log.info("A log message to the console!!!!");
That's it really. Now you have complete control. It's almost always best to use a logger to control output in general. System.XXX.println's can't be controlled via a central configuration and you will forget to remove them later. Also you can add additional appenders to persist output like so:
# LOGFILE is set to be a File appender using a PatternLayout.
log4j.appender.LOGFILE=org.apache.log4j.RollingFileAppender
log4j.appender.LOGFILE.Threshold=INFO
log4j.appender.LOGFILE.MaxFileSize=5MB
log4j.appender.LOGFILE.File=mylogfile.log
log4j.appender.LOGFILE.Append=true
log4j.appender.LOGFILE.layout=org.apache.log4j.PatternLayout
log4j.appender.LOGFILE.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %p [%c]: %m%n
This will generate a mylogfile.log and will keep the files at 5MB max and will keep several (forget the default) versions with a timestamp appended.
I hope that helps. log4j has been around forever and is excellent. There are more tutorials on the web than you can shake a stick at.
Upvotes: 2
Reputation: 310
It's not the right practice but you could switch to System.err.println() as a switch instead to capture values in console. The right approach will be to use loggers (like log4j) as pointed in comments.
Upvotes: 2