title: Logging Spring using Log4j2
body: <p>I'm trying to use <strong>Log4j2</strong> to print the spring logs into a file and console. I guess it is a problem in my Log4j2 configuration. I have not been able to get it working. I have this configuration in my log4j2.xml file:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;configuration name="defaultConfiguration" status="warn" strict="true" monitorInterval="5"&gt;
      &lt;properties&gt;
          &lt;property name="patternlayout"&gt;%d{ISO8601} [%t] %-5level %logger{36} - %msg%n%throwable{full}&lt;/property&gt;
          &lt;property name="filename"&gt;${env:MY_ROOT}/logs/mylog.log&lt;/property&gt;
          &lt;property name="filenamePattern"&gt;${env:MY_ROOT}/logs/mylog-%d{yyyy-dd-MM}-%i.log.gz&lt;/property&gt;
      &lt;/properties&gt;
      &lt;appenders&gt;
          &lt;appender name="Console" type="Console" target="SYSTEM_OUT"&gt;
              &lt;layout type="PatternLayout" pattern="${patternlayout}" /&gt;
          &lt;/appender&gt;
          &lt;appender name="File" type="RollingFile" fileName="${filename}" filePattern="${filenamePattern}" bufferedIO="true" immediateFlush="true"
          append="true"&gt;
              &lt;layout type="PatternLayout" pattern="${patternlayout}" /&gt;
              &lt;Policies&gt;
                  &lt;TimeBasedTriggeringPolicy /&gt;
                  &lt;SizeBasedTriggeringPolicy size="50 MB" /&gt;
              &lt;/Policies&gt;
              &lt;DefaultRolloverStrategy max="30" /&gt;
          &lt;/appender&gt;
          &lt;appender name="AsynchFile" type="asynch" blocking="true" bufferSize="128"&gt;
              &lt;appender-ref ref="File" /&gt;
          &lt;/appender&gt;
      &lt;/appenders&gt;
      &lt;loggers&gt;
          &lt;root level="info"&gt;
              &lt;appender-ref ref="Console" /&gt;
              &lt;appender-ref ref="AsynchFile" /&gt;
          &lt;/root&gt;
          &lt;logger name="org.springframework.beans"&gt;
              &lt;appender-ref ref="Console" /&gt;
              &lt;appender-ref ref="AsynchFile" /&gt;
          &lt;/logger&gt;
      &lt;/loggers&gt;
  &lt;/configuration&gt;
  </code></pre>
  
  <p>These are the dependencies that I have in my pom file: (probably some of them are not required)</p>
  
  <pre><code>&lt;dependency&gt;
   &lt;groupId&gt;org.slf4j&lt;/groupId&gt;
   &lt;artifactId&gt;slf4j-api&lt;/artifactId&gt;
   &lt;version&gt;1.6.6&lt;/version&gt;
  &lt;/dependency&gt;
  
  &lt;dependency&gt;
   &lt;groupId&gt;org.slf4j&lt;/groupId&gt;
   &lt;artifactId&gt;slf4j-log4j12&lt;/artifactId&gt;
   &lt;version&gt;1.6.6&lt;/version&gt;
  &lt;/dependency&gt;
  
  &lt;dependency&gt;
   &lt;groupId&gt;org.apache.logging.log4j&lt;/groupId&gt;
   &lt;artifactId&gt;log4j-api&lt;/artifactId&gt;
   &lt;version&gt;2.0-beta5&lt;/version&gt;
  &lt;/dependency&gt;
  
  &lt;dependency&gt;
   &lt;groupId&gt;org.apache.logging.log4j&lt;/groupId&gt;
   &lt;artifactId&gt;log4j-core&lt;/artifactId&gt;
   &lt;version&gt;2.0-beta5&lt;/version&gt;
  &lt;/dependency&gt;
  &lt;dependency&gt;
   &lt;groupId&gt;org.apache.logging.log4j&lt;/groupId&gt;
   &lt;artifactId&gt;log4j-1.2-api&lt;/artifactId&gt;
   &lt;version&gt;2.0-beta5&lt;/version&gt;
  &lt;/dependency&gt;
  
  &lt;dependency&gt;
   &lt;groupId&gt;com.lmax&lt;/groupId&gt;
   &lt;artifactId&gt;disruptor&lt;/artifactId&gt;
   &lt;version&gt;3.0.0.beta3&lt;/version&gt;
  &lt;/dependency&gt;
  </code></pre>
  
  <p>I'm not doing anything related to spring in my Java code. I'm using the Main class from Apache Camel which reads my spring configuration and loads the beans.</p>
  
  <p>What am I doing wrong? Thanks!</p>
  
  <p>Edit: I am not getting spring logs in any output (console or file). However, I am able to get the logs I create in my java code. I hope this clarification will help.</p>