How to View Tomcat Log Files in Eclipse

Where can I view Tomcat log files in Eclipse?

Go to the "Server" view, then double-click the Tomcat server you're running. The access log files are stored relative to the path in the "Server path" field, which itself is relative to the workspace path.

Tomcat console output in Eclipse: where is my System.out.print() output, how to debug?

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.

Java web app catalina logs not written to log file when running in Eclipse

This answer resolved my question: https://stackoverflow.com/a/5045247/3368818

Apparently, if, while running an app on tomcat via Eclipse, you want to capture the catalina logs in a file, you need to specify that via the Eclipse tomcat launch configuration settings.

I guess in a way this makes sense in that the catalina logs are perhaps not application specific, so maybe outside the scope of logback appenders. But on the other hand, shouldn't they get written to a log file by default anyway, just as they do if you launch your tomcat server outside of Eclipse?

Tomcat ignores logging.properties when started from Eclipse

Tomcat that is started from Eclipse uses configuration that is specified in its Properties. By default, logging configuration is not specified.

So, open Eclipse -> select Tomcat -> Properties, click Open Launch configurationand in Arguments tab add -Djava.util.logging.config.file="your-tomcat-folder\conf\logging.properties" -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager.



Related Topics



Leave a reply



Submit