Hello,We are reproducing the following ERROR multiple times per Tomcat 7.x startup in multiple dev and test environments:2025-05-07 15:21:39,599 http-bio-8081-exec-4 ERROR Unable to lookup java:comp/env/log4j/context-name javax.naming.NameNotFoundException: Name [log4j/context-name] is not bound in this Context. Unable to find [log4j]. at org.apache.naming.NamingContext.lookup(NamingContext.java:825) at org.apache.naming.NamingContext.lookup(NamingContext.java:159) at org.apache.naming.NamingContext.lookup(NamingContext.java:836) at org.apache.naming.NamingContext.lookup(NamingContext.java:159) at org.apache.naming.NamingContext.lookup(NamingContext.java:836) at org.apache.naming.NamingContext.lookup(NamingContext.java:173) at org.apache.naming.SelectorContext.lookup(SelectorContext.java:156) at java.naming/javax.naming.InitialContext.lookup(InitialContext.java:409) at org.apache.logging.log4j.core.net.JndiManager.lookup(JndiManager.java:172) at org.apache.logging.log4j.core.selector.JndiContextSelector.getContext(JndiContextSelector.java:112) at org.apache.logging.log4j.core.selector.JndiContextSelector.getContext(JndiContextSelector.java:97) at org.apache.logging.log4j.core.impl.Log4jContextFactory. Based on some research on this error, I'm seeing the following potential remediation:Tomcat 7 does not automatically populate JNDI environment entries from web.xml alone.
For Tomcat 7.x specifically: You must define the log4j/context-name JNDI resource in context.xml, either: Inside the META-INF/context.xml of your web application, or In $CATALINA_BASE/conf/context.xml (applies to all apps), or In per-app context files, e.g., $CATALINA_BASE/conf/Catalina/localhost/yourapp.xml Example for META-INF/context.xml in your WAR: <Context> <Environment name="log4j/context-name" type="java.lang.String" value="MyAppContext"/> </Context> This tells Tomcat to bind the log4j/context-name in the java:comp/env namespace, so when Log4j tries to look it up, it can find it. I was able to resolve it (i.e. such that it is no longer output in the console during catalina startup) by adding the following XML snippet in $CATALINA_BASE/conf/context.xml:<Environment name="log4j/context-name" type="java.lang.String" value="base2" /> and removing below in web.xml:<env-entry> <env-entry-name>log4j/context-name</env-entry-name> <env-entry-value>base2</env-entry-value> <env-entry-type>java.lang.String</env-entry-type> </env-entry> NOTE: I had base, base2 and base3 apps deployed in $CATALINA_BASE/webapps dir. base2 and base3 were setup for separated logging and above removal in web.xml was done in base2 and base3 web.xml files. It's not possible afaik to add multiple environment variables like above in $CATALINA_BASE/conf/context.xml, one for each app as I'm not sure it's possible to have more than one entry for a distinct environment name.NOTE2: Prior to attempting above solution, I tried the web.xml removals and adding to META-INF/context.xml as below:<Environment name="log4j/context-name" type="java.lang.String" value="base2" /> for base2 and base3 however that had no effect apparently and the unable to lookup error reproduces.Please advise if there is something missing or any alternate/better strategy for removing the ERROR loggings from the logs.Arbi Sookazian | Sr Software Engineer | Medata, Inc. 5 Peters Canyon Road, Suite 250 Irvine, CA 92606 asookaz...@medata.com | www.medata.com