We are using Tomcat 7.0.54.
The web.xml:
<context-param> <param-name>log4jContextName</param-name>
<param-value>SabaLog4jContext</param-value> </context-param>
There is sample servlet which starts on load
<servlet> <servlet-name>startUp</servlet-name>
<servlet-class>foo.StartupServlet</servlet-class>
<load-on-startup>1</load-on-startup> </servlet>
The StartupServlet simple as:
public class StartupServlet extends HttpServlet { @Override
public void init() throws ServletException {
getServletContext().setAttribute("test", "ATest"); super.init();
} }
The log4j2 can not access the `test` attribute with `${web:attr.test}` and I
got the warning as:
INFO: org.apache.logging.log4j.web.WebLookup unable to resolve key 'test'
It seems that Log4j2 works fine but the problem is that it starts before my
Startup. I tried to use a `servletContextListener` class but no luck.
I also tried to disable Log4jAutoInitialization in web.xml and manually start
set them as below.
<listener>
<listener-class>org.apache.logging.log4j.web.Log4jServletContextListener</listener-class>
</listener> <filter>
<filter-name>log4jServletFilter</filter-name>
<filter-class>org.apache.logging.log4j.web.Log4jServletFilter</filter-class>
</filter> <filter-mapping>
<filter-name>log4jServletFilter</filter-name>
<url-pattern>/*</url-pattern> <dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher> <dispatcher>INCLUDE</dispatcher>
<dispatcher>ERROR</dispatcher> </filter-mapping>
But no luck:(
The log4j2.xml is as below:
<property name="baseFolder">${web:rootDir}/../logs/${web:test}</property>
So how can setup my web.xml so that my code execute before Log4j context.
The `web.xml` also contains spring Listeners as:
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener> <listener>
<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>
~Regards,
~~Alireza Fattahi