Hi all, I have a small web app that runs in Tomcat 9 and uses log4j 2 for logging. This works in one case and does not work in another case:
Case 1: When I deploy the war file to Tomcat (copying the war file to the Tomcat webapps folder), everything works as expected. The log file is created (if missing) and the app’s log output appears in the log file. In the catalina log file I see that the Log4j context has been initialized (the two 'GW.war' lines are being written to stdout by my app): 13-Mar-2024 20:49:02.229 INFORMATION [Catalina-utility-1] org.apache.catalina.startup.HostConfig.deployWAR Deploying web application archive [/Users/piers/Documents/Tomcat/apache-tomcat-9.0.86/webapps/GW.war] 13-Mar-2024 20:49:02.475 INFORMATION [Catalina-utility-1] org.apache.jasper.servlet.TldScanner.scanJars At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time. GW.war: ServletContextListener started GW.war: System property log4j.configurationFile=/Users/piers/Documents/Tomcat/apache-tomcat-9.0.86/conf/ilink-LDAP-GW-log4j2.xml 2024-03-13T19:49:02.609143Z Catalina-utility-1 INFO Log4jServletContextListener triggered a Log4j context initialization. 13-Mar-2024 20:49:02.646 INFORMATION [Catalina-utility-1] org.apache.catalina.startup.HostConfig.deployWAR Deployment of web application archive [/Users/piers/Documents/Tomcat/apache-tomcat-9.0.86/webapps/GW.war] has finished in [417] ms Case 2: However, if I stop and restart the Tomcat service (with the war file having been previously deployed), the app no longer logs anything and I don’t see a catalina log line about Log4j context initialization: 13-Mar-2024 20:49:34.329 INFORMATION [main] org.apache.catalina.startup.HostConfig.deployWAR Deploying web application archive [/Users/piers/Documents/Tomcat/apache-tomcat-9.0.86/webapps/GW.war] 13-Mar-2024 20:49:34.609 INFORMATION [main] org.apache.jasper.servlet.TldScanner.scanJars At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time. GW.war: ServletContextListener started GW.war: System property log4j.configurationFile=/Users/piers/Documents/Tomcat/apache-tomcat-9.0.86/conf/ilink-LDAP-GW-log4j2.xml 13-Mar-2024 20:49:34.781 INFORMATION [main] org.apache.catalina.startup.HostConfig.deployWAR Deployment of web application archive [/Users/piers/Documents/Tomcat/apache-tomcat-9.0.86/webapps/GW.war] has finished in [452] ms I am not sure what I might be doing wrong here. I see that the deployment is being reported using different logger names (thread names?) in both cases: [Catalina-utility-1] vs. [main]. I don’t know if this should make a difference though. The app uses the servlet API 3.1. I included log4j-web-2.23.0.jar in WEB-INF/lib for proper initialization. (also included are log4j-api-2.23.0.jar, log4j-core-2.23.0.jar, and log4j-slf4j-impl-2.23.0.jar in case this might be relevant) I configured a servlet context listener in order to be able to set the system property log4j.configurationFile upon application start. This allows me to place the log4j configuration file outside of the war file. This is my web.xml: <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1"> <listener> <!-- Adding a servlet context listener to execute code before the application is being initialized. --> <listener-class>de.ilink.cloud.ucc.gw.LdapGwServletContextListener</listener-class> </listener> </web-app> I’m stuck at this point and would appreciate any ideas of what might be going on here. Piers -- Piers Uso Walter <piers.wal...@ilink.de> ilink Kommunikationssysteme GmbH --------------------------------------------------------------------- To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org For additional commands, e-mail: log4j-user-h...@logging.apache.org