I can't seem to get java.util.logging to work with tomcat after I redeploy a webapp. Here is a very simple Servlet as a test case;
package test;
import java.util.logging.Logger;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
@WebServlet(name = "TestLogServlet", urlPatterns = {"/TestLogServlet"}, loadOnStartup=1)
public class TestLogServlet extends HttpServlet {
private Logger logger = Logger.getLogger(TestLogServlet.class.getName());
@Override
public void init(ServletConfig config) throws ServletException {
super.init(config);
System.out.println("my log message to system.out");
logger.info("my log message to logger");
}
}
If I have the webapp installed, then start tomcat, I will see in the logs (catalina.out) the following, as expected;
my log message to system.out
20-Mar-2023 10:56:37.035 INFO [main] test.TestLogServlet.init my log message to logger
Both the system.out and the logger message.
If I then undeploy the webapps, then redeploy it in the running tomcat, all I will see in the logs are;
my log message to system.out
Nothing else will appear comming from java.util.logger.
What am I missing, or doing wrong? It's driving me mad!
A bit of an update... This is why ...
==> catalina.out <==
my log message to system.out
==> catalina.2023-03-20.log <==
20-Mar-2023 11:42:04.041 INFO [http-nio-8080-exec-16] test.TestLogServlet.init my log message to logger
After a redeploy, it goes to catalina.2023-03-20.log, not catalina.out. When you restart tomcat it goes to catalina.2023-03-20.log and catalina.out!!
So, how does I get the logger messages to ALWAYS go to catalina.out?
I tired this on a tomcat8, and it does seem to always go to catalina.out there.
You could custom the log format through the configure file there should be a default file log4j.properties in path $CATALINA_BASE/lib
Create one, if there isn't.
and add the following to logging.properties file
You could also read the Tomcat logging documentation.