Is there a way to log all stdout output to the catalina.log file in Tomcat? (i.e. everything that gets printed to System.out.println()
)
The console window that opens when you run TOMCAT/bin/startup.bat
displays output from stdout, but it's not saved to TOMCAT/logs/catalina.<date>.log
.
My specific problem is that I have a console appender defined in log4j to output to the console. These log messages appear correctly in the Tomcat console window, but they are not written to catalina.log. I'm running Tomcat 5.5 on Windows. Thanks.
EDIT:
Here is my log4j.properties file. It is located at TOMCAT/webapps/app/WEB-INF/classes/log4j.properties
:
log4j.rootCategory=DEBUG, console
log4j.appender.console=org.apache.log4j.ConsoleAppender
log4j.appender.console.layout=org.apache.log4j.PatternLayout
log4j.appender.console.layout.ConversionPattern=[%d{ABSOLUTE} %-5p %c{1}]: %m%n
Each server instance contains its own Catalina.This file is located in the logs directory below the Tomcat root directory. This log is the system's output log, which also consists of standard error messages. These files are saved daily (MM-DD-YYYY) with the date appended to the name of the data.
Tomcat Access Logs The access log records all requests processed by the server. As of Tomcat 7, enabled in Tomcat by default in ${tomcat_home}/conf/server. xml . Information it contains is different from other logs in ${tomcat_home}/logs .
The Apache Tomcat logs are an essential feature that allows sysadmins to view what is accessed and how the server handles the various resources. Although you can implement logging for the Java applications written for Tomcat, getting the internal webserver logs can be instrumental in troubleshooting.
Catalina Log: This is the global log. It records information about events such as the startup and shutdown of the Tomcat application server, the deployment of new applications, or the failure of one or more subsystems.
I've come across similar questions before, and haven't found a way to do this by logging System.out in Windows unless you are running Tomcat as a Windows service. This seems to work by default in Unix since startup.sh
points to catalina.sh
which logs stdout to the catalina.out
file like below
org.apache.catalina.startup.Bootstrap "$@" start >> "$CATALINA_BASE"/logs/catalina.out 2>&1 &
In log4j, ConsoleAppender
by itself does not append to a File, only to System.out
However, I've modified your log4j properties to add a FileAppender and this config works, but of course this logs into a separate log file.
New config
# Set root logger level to DEBUG.
log4j.rootLogger=DEBUG, console, myFile
log4j.appender.console=org.apache.log4j.ConsoleAppender
log4j.appender.console.layout=org.apache.log4j.PatternLayout
log4j.appender.console.layout.ConversionPattern=[%d{ABSOLUTE} %-5p %c{1}]: %m%n
# myFile writes to file
log4j.appender.myFile=org.apache.log4j.RollingFileAppender
log4j.appender.myFile.File=logs/tomcatlog4j.log
log4j.appender.myFile.MaxFileSize=100KB
log4j.appender.myFile.layout=org.apache.log4j.PatternLayout
log4j.appender.myFile.layout.ConversionPattern==[%d{ABSOLUTE} %-5p %c{1}]: %m%n
Output
=[15:24:03,819 INFO A1]: In my.jsp =[15:24:03,975 INFO A1]: Out of my.jsp =[15:24:04,880 INFO A1]: In my.jsp =[15:24:04,880 INFO A1]: Out of my.jsp
also see
How to log exceptions from a specific package deployed in tomcat
log select events into a separate file
https://serverfault.com/questions/201178/tomcat-5-5-how-to-redirect-the-logging-output-to-one-file-per-web-application
Did you checked, whether the log4j.properties file can be found from your application? Maybe you can check, by setting a hardcoded file path like
-Dlog4j.configuration=file:///C:\Dev\log4j.properties
If the logs are written after these change, the relativ path to the log4j file is wrong.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With