title: how to configure log4j2 webapplication
body: <p>Am little new to web applications, recently I was in need to employ a logging mechanism and for that I choose Log4J2, I went through there guide, and downloaded required libraries. This is what so far I did.</p>
  
  <pre><code>1. Added following jars to web-inf/lib
     --  log4j-core2.1.jar
     --  log4j-api-2.1.jar
     --  log4j-web-2.1.jar
  
  
  2. Added below xml as, log4j2.xml in java/src directory
  
  &lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;configuration name="NONPROD" status="OFF"&gt;
  
  
      &lt;Properties&gt;
  
          &lt;Property name="log-path"&gt;logs&lt;/Property&gt;
      &lt;/Properties&gt;
  
  
      &lt;Appenders&gt;
  
          &lt;Console name="console-log" target="SYSTEM_OUT"&gt;
              &lt;!-- &lt;pattern&gt;[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n --&gt;
              &lt;!-- &lt;/pattern&gt; --&gt;
  
              &lt;PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n" /&gt;
          &lt;/Console&gt;
  
  
          &lt;RollingFile name="info-log" fileName="${log-path}/web-info.log"
              filePattern="${log-path}/web-info-%d{yyyy-MM-dd}.log"&gt;
              &lt;PatternLayout&gt;
                  &lt;pattern&gt;[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n
                  &lt;/pattern&gt;
              &lt;/PatternLayout&gt;
              &lt;Policies&gt;
                  &lt;TimeBasedTriggeringPolicy interval="1"
                      modulate="true" /&gt;
  
                  &lt;OnStartupTriggeringPolicy /&gt;
                  &lt;SizeBasedTriggeringPolicy size="20 MB" /&gt;
              &lt;/Policies&gt;
          &lt;/RollingFile&gt;
  
          &lt;RollingFile name="error-log" fileName="${log-path}/web-error.log"
              filePattern="${log-path}/web-error-%d{yyyy-MM-dd}.log"&gt;
              &lt;PatternLayout&gt;
                  &lt;pattern&gt;[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n
                  &lt;/pattern&gt;
              &lt;/PatternLayout&gt;
              &lt;Policies&gt;
                  &lt;TimeBasedTriggeringPolicy interval="1"
                      modulate="true" /&gt;
  
                  &lt;OnStartupTriggeringPolicy /&gt;
                  &lt;SizeBasedTriggeringPolicy size="20 MB" /&gt;
              &lt;/Policies&gt;
          &lt;/RollingFile&gt;
  
  
          &lt;RollingFile name="debug-log" fileName="${log-path}/web-debug.log"
              filePattern="${log-path}/web-debug-%d{yyyy-MM-dd}.log"&gt;
              &lt;PatternLayout&gt;
                  &lt;pattern&gt;[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n
                  &lt;/pattern&gt;
              &lt;/PatternLayout&gt;
              &lt;Policies&gt;
                  &lt;TimeBasedTriggeringPolicy interval="1"
                      modulate="true" /&gt;
  
                  &lt;OnStartupTriggeringPolicy /&gt;
                  &lt;SizeBasedTriggeringPolicy size="20 MB" /&gt;
              &lt;/Policies&gt;
          &lt;/RollingFile&gt;
  
  
  
          &lt;RollingFile name="trace-log" fileName="${log-path}/web-trace.log"
              filePattern="${log-path}/web-trace-%d{yyyy-MM-dd}.log"&gt;
              &lt;PatternLayout&gt;
                  &lt;pattern&gt;[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n
                  &lt;/pattern&gt;
              &lt;/PatternLayout&gt;
              &lt;Policies&gt;
                  &lt;TimeBasedTriggeringPolicy interval="1"
                      modulate="true" /&gt;
  
                  &lt;OnStartupTriggeringPolicy /&gt;
                  &lt;SizeBasedTriggeringPolicy size="20 MB" /&gt;
              &lt;/Policies&gt;
          &lt;/RollingFile&gt;
  
      &lt;/Appenders&gt;
  
      &lt;Loggers&gt;
  
          &lt;Logger name="com.demo.web.log4j2.file" level="debug"
              additivity="false"&gt;
  
              &lt;appender-ref ref="trace-log" level="trace" /&gt;
  
              &lt;appender-ref ref="error-log" level="error" /&gt;
  
              &lt;appender-ref ref="debug-log" level="debug" /&gt;
  
              &lt;appender-ref ref="info-log" level="info" /&gt;
          &lt;/Logger&gt;
  
          &lt;Logger name="com.demo.web.log4j2.console" level="all"
              additivity="false"&gt;
              &lt;AppenderRef ref="console-log" /&gt;
          &lt;/Logger&gt;
  
  
          &lt;Root level="info" additivity="true"&gt;
  
              &lt;AppenderRef ref="console-log" /&gt;
  
          &lt;/Root&gt;
  
      &lt;/Loggers&gt;
  
  
  &lt;/configuration&gt;
  
  3. third and last i wrote an small web service to test logging
  
  @Path("/register")
  public class Register {
  
      private DataManager mManager;
       private static final Logger LOG = LogManager.getLogger(Register.class);
  
      public Register(){
          mManager = DataManager.getInstance();
      }
  
  
      @GET
      @Path("/{param}")
      public Response getMsg(@PathParam("param") String msg) {
  
          LOG.error("Not supported operations");
          return Response.status(Response.Status.BAD_REQUEST)
                  .entity("Not supported").build();
  
      }
  </code></pre>
  
  <p>But in console, upon trigger get request this is all i got printed.</p>
  
  <pre><code>INFO: Server startup in 35959 ms
  Not supported operations // this is not in pattern i supplied in log4j2.xml
  
  // this is my pattern
              &lt;PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n" /&gt;
  </code></pre>
  
  <p>I figure out this is probably due to some thing gone wrong, and am struggling to find the actual cause, being totally new to web programming, please help me out to configure my logger.</p>
  
  <p>Thanks,
  Techfist</p>