Note that there are some explanatory texts on larger screens.

plurals
  1. POlog4j2 configuration is not loaded
    primarykey
    data
    text
    <p>Can you help me spotting out the missing step for my configuration?</p> <p>I'm trying to add logger to my very simple web application: in order to do so I'm using log4j2 (beta9).</p> <p>I wrote down my <code>log4j2.xml</code> as follows</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;Configuration status="WARN"&gt; &lt;Appenders&gt; &lt;Console name="Console" target="SYSTEM_OUT"&gt; &lt;PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} /%L/[%M] - %msg%n"/&gt; &lt;/Console&gt; &lt;/Appenders&gt; &lt;Loggers&gt; &lt;Logger name="prova.Hello" level="trace" additivity="false"&gt; &lt;AppenderRef ref="Console"/&gt; &lt;/Logger&gt; &lt;Logger name="servletstest.TestLogger" level="trace" additivity="false"&gt; &lt;AppenderRef ref="Console"/&gt; &lt;/Logger&gt; &lt;Root level="trace"&gt; &lt;AppenderRef ref="Console"/&gt; &lt;/Root&gt; &lt;/Loggers&gt; &lt;/Configuration&gt; </code></pre> <p>and I put it in the WEB-INF folder.</p> <p>I have then a simple servlet which does the following </p> <pre><code>response.setContentType("text/html;charset=UTF-8"); PrintWriter out = response.getWriter(); try { /* TODO output your page here. You may use following sample code. */ out.println("&lt;!DOCTYPE html&gt;"); out.println("&lt;html&gt;"); out.println("&lt;head&gt;"); out.println("&lt;title&gt;Servlet TestLogger&lt;/title&gt;"); out.println("&lt;/head&gt;"); out.println("&lt;body&gt;"); out.println("&lt;h1&gt;Servlet TestLogger at " + request.getContextPath() + "&lt;/h1&gt;"); out.println("&lt;/body&gt;"); out.println("&lt;/html&gt;"); logger.error("error"); logger.info("info"); logger.trace("trace"); logger.debug("debug"); } finally { out.close(); } </code></pre> <p>As you can see it is just a try to see if the logger works as expected, but it does not. By reading here <a href="http://logging.apache.org/log4j/2.x/manual/webapp.html" rel="nofollow">web app</a> I don't need to configure the web.xml of my application because it runs servlet 3.0, infact if I try to add the configuration I get the following error</p> <pre><code>javax.servlet.UnavailableException: In a Servlet 3.0+ application, you must not define a log4jServletFilter in web.xml. Log4j 2 defines this for you automatically. </code></pre> <p>But it seems not to load the log4j2 configuration file, since the output I excpect is similar to </p> <pre><code>10:57:55.490 [http-bio-8084-exec-5] ERROR servletstest.TestLogger - error 10:57:55.490 [http-bio-8084-exec-5] INFO servletstest.TestLogger - info 10:57:55.490 [http-bio-8084-exec-5] TRACE servletstest.TestLogger - trace 10:57:55.490 [http-bio-8084-exec-5] DEBUG servletstest.TestLogger - debug </code></pre> <p>instead I get only</p> <pre><code>10:57:55.490 [http-bio-8084-exec-5] ERROR servletstest.TestLogger - error </code></pre> <p>it looks like is not able to load the xml file and it sets by default the logger level to error only. In the same web page is written </p> <blockquote> <p>In Tomcat 7 &lt;7.0.43 you will need to change catalina.properties and remove "log4j*.jar" from the jarsToSkip property. You may need to do something similar on other containers if they skip scanning Log4j JAR files.</p> </blockquote> <p>so I edited the catalina.properties becasuse I'm running tomcat 7.0.41 and I removed the log4j*.jar from the <code>jartoskip</code> property.</p> <p>What am I doing wrong?</p> <p>by the way in the web.xml I have this</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;web-app id="WebApp_ID" version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"&gt; &lt;display-name&gt;test&lt;/display-name&gt; &lt;servlet&gt; &lt;servlet-name&gt;Jersey REST Service&lt;/servlet-name&gt; &lt;servlet-class&gt;org.glassfish.jersey.servlet.ServletContainer&lt;/servlet-class&gt; &lt;init-param&gt; &lt;param-name&gt;jersey.config.server.provider.packages&lt;/param-name&gt; &lt;param-value&gt;prova&lt;/param-value&gt; &lt;/init-param&gt; &lt;load-on-startup&gt;1&lt;/load-on-startup&gt; &lt;/servlet&gt; &lt;servlet&gt; &lt;servlet-name&gt;TestLogger&lt;/servlet-name&gt; &lt;servlet-class&gt;servletstest.TestLogger&lt;/servlet-class&gt; &lt;/servlet&gt; &lt;servlet-mapping&gt; &lt;servlet-name&gt;Jersey REST Service&lt;/servlet-name&gt; &lt;url-pattern&gt;/rest/*&lt;/url-pattern&gt; &lt;/servlet-mapping&gt; &lt;servlet-mapping&gt; &lt;servlet-name&gt;TestLogger&lt;/servlet-name&gt; &lt;url-pattern&gt;/TestLogger&lt;/url-pattern&gt; &lt;/servlet-mapping&gt; &lt;listener&gt; &lt;listener-class&gt;org.apache.logging.log4j.core.web.Log4jServletContextListener&lt;/listener-class&gt; &lt;/listener&gt; &lt;/web-app&gt; </code></pre> <p>You can notice that <code>version</code> is 2.5 and not properly 3.0 is perhaps this affecting me somehow? or jersey configuration?</p> <p>EDIT: I tried again and changed the <code>web.xml</code> to the following in order to have a web app version of 3.0 but it does not load the configuration.. what am I doing wrong?</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"&gt; &lt;servlet&gt; &lt;servlet-name&gt;Prova&lt;/servlet-name&gt; &lt;servlet-class&gt;test.Prova&lt;/servlet-class&gt; &lt;/servlet&gt; &lt;servlet-mapping&gt; &lt;servlet-name&gt;Prova&lt;/servlet-name&gt; &lt;url-pattern&gt;/Prova&lt;/url-pattern&gt; &lt;/servlet-mapping&gt; &lt;session-config&gt; &lt;session-timeout&gt; 30 &lt;/session-timeout&gt; &lt;/session-config&gt; &lt;/web-app&gt; </code></pre> <p>thanks in advance for the help. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload