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 configuration
and 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
Use Java and Regex to Convert Casing in a String
Sorting an Array of Int Using Bubblesort
What Does Maven Do, in Theory and in Practice? When Is It Worth to Use It
The Concatenation of Chars to Form a String Gives Different Results
Is There a Good Reason to Use "Printf" Instead of "Print" in Java
Facebook Offline Access Step-By-Step
Difference Between One-To-Many, Many-To-One and Many-To-Many
Converting a Jfreechart Timeseries Series with Day Data to Week or Month Data
Why We Shouldn't Make a Spring MVC Controller @Transactional
Use Custom Manifest File and Permission in Unity
How to Create a .Jar File or Export Jar in Intellij Idea (Like Eclipse Java Archive Export)
Best Option for Session Management in Java
Collections.Emptylist() VS. New Instance
Spring Crudrepository Findbyinventoryids(List<Long> Inventoryidlist) - Equivalent to in Clause
Differencebetween Getfields and Getdeclaredfields in Java Reflection