logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Alireza Fattahi <afatt...@yahoo.com.INVALID>
Subject Log4j2 web look up cannot access servletcontext attribute
Date Mon, 15 Dec 2014 04:50:18 GMT
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> 
  <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
    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
     <listener>        <listener-class>org.apache.logging.log4j.web.Log4jServletContextListener</listener-class> 
  </listener>         <filter>       <filter-name>log4jServletFilter</filter-name> 
  </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> 
~~Alireza Fattahi
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message