title: Override log4j.properties during testing
body: <p>I want to log only the <code>ERROR</code> during testing in maven. For this purpose I created a file <code>src/test/resources/log4j.properties</code>, which is going to override the configuration I already have in <code>src/main/resources/log4j.properties</code>. But this is not working. My <code>log4j.properties</code> looks like below:-</p>
  
  <pre><code>log4j.rootLogger=ERROR, out, stdout
  
  # CONSOLE appender
  log4j.appender.stdout=org.apache.log4j.ConsoleAppender
  log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
  log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd'T'HH:mm:ss.SSSZ} | %-5.5p | %-16.16t | %-32.32c{1} | %X{bundle.id} - %X{bundle.name} - %X{bundle.version} | %X | %m%n
  #log4j.logger.org.apache.http=INFO
  
  # File appender
  log4j.appender.out=org.apache.log4j.DailyRollingFileAppender
  log4j.appender.out.File=/tmp/wf_test.log
  log4j.appender.out.DatePattern='.'yyyy-MM-dd
  log4j.appender.out.Append=true
  log4j.appender.out.layout=org.apache.log4j.PatternLayout
  log4j.appender.out.layout.ConversionPattern=%d{yyyy-MM-dd'T'HH:mm:ss.SSSZ} | %-5.5p | %-16.16t | %-32.32c{1} | %X{bundle.id} - %X{bundle.name} - %X{bundle.version} | %X | %m%n
  </code></pre>
  
  <p>My <code>pom.xml</code> looks like below:-</p>
  
  <pre><code>&lt;project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"&gt;
      &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
  
      &lt;groupId&gt;com.jabong.orchestratorservice&lt;/groupId&gt;
      &lt;artifactId&gt;basecomponent&lt;/artifactId&gt;
      &lt;version&gt;0.0.1&lt;/version&gt;
      &lt;packaging&gt;bundle&lt;/packaging&gt;
      &lt;name&gt;basecomponent&lt;/name&gt;
      &lt;url&gt;http://maven.apache.org&lt;/url&gt;
  
      &lt;properties&gt;
          &lt;project.build.sourceEncoding&gt;UTF-8&lt;/project.build.sourceEncoding&gt;
          &lt;camel.version&gt;2.16.1&lt;/camel.version&gt;
          &lt;jackson.version&gt;2.7.4&lt;/jackson.version&gt;
          &lt;jackson.afterburner.version&gt;2.7.1&lt;/jackson.afterburner.version&gt;
          &lt;runSuite&gt;**/AllTestSuite.class&lt;/runSuite&gt;
          &lt;sonar.host.url&gt;http://sonar:9000/&lt;/sonar.host.url&gt;
          &lt;sonar.jdbc.username&gt;sonar&lt;/sonar.jdbc.username&gt;
          &lt;sonar.jdbc.password&gt;sonar&lt;/sonar.jdbc.password&gt;
          &lt;sonar.jdbc.url&gt;jdbc:mysql://sonar:3306/sonar?useUnicode=true&amp;amp;characterEncoding=utf8&lt;/sonar.jdbc.url&gt;
          &lt;sonar.jdbc.driverClassName&gt;com.mysql.jdbc.Driver&lt;/sonar.jdbc.driverClassName&gt;      
          &lt;sonar.binaries&gt;target&lt;/sonar.binaries&gt;
          &lt;sonar.tests&gt;src/test&lt;/sonar.tests&gt;
          &lt;sonar.dynamicAnalysis&gt;reuseReports&lt;/sonar.dynamicAnalysis&gt;
          &lt;sonar.junit.reportsPath&gt;build/test-reports&lt;/sonar.junit.reportsPath&gt;
          &lt;sonar.java.coveragePlugin&gt;jacoco&lt;/sonar.java.coveragePlugin&gt;
          &lt;sonar.core.codeCoveragePlugin&gt;jacoco&lt;/sonar.core.codeCoveragePlugin&gt;
          &lt;sonar.dynamicAnalysis&gt;reuseReports&lt;/sonar.dynamicAnalysis&gt;
          &lt;sonar.jacoco.reportPath&gt;${project.basedir}/../target/jacoco.exec&lt;/sonar.jacoco.reportPath&gt;
      &lt;/properties&gt;
  
      &lt;dependencies&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;commons-fileupload&lt;/groupId&gt;
              &lt;artifactId&gt;commons-fileupload&lt;/artifactId&gt;
              &lt;version&gt;1.3.1&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;commons-httpclient&lt;/groupId&gt;
              &lt;artifactId&gt;commons-httpclient&lt;/artifactId&gt;
              &lt;version&gt;3.1&lt;/version&gt;
              &lt;scope&gt;test&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.hsqldb&lt;/groupId&gt;
              &lt;artifactId&gt;hsqldb&lt;/artifactId&gt;
              &lt;version&gt;2.3.3&lt;/version&gt;
              &lt;scope&gt;test&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;junit&lt;/groupId&gt;
              &lt;artifactId&gt;junit&lt;/artifactId&gt;
              &lt;version&gt;4.12&lt;/version&gt;
              &lt;scope&gt;test&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;com.fasterxml.jackson.core&lt;/groupId&gt;
              &lt;artifactId&gt;jackson-core&lt;/artifactId&gt;
              &lt;version&gt;${jackson.version}&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;com.fasterxml.jackson.core&lt;/groupId&gt;
              &lt;artifactId&gt;jackson-annotations&lt;/artifactId&gt;
              &lt;version&gt;${jackson.version}&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;com.fasterxml.jackson.core&lt;/groupId&gt;
              &lt;artifactId&gt;jackson-databind&lt;/artifactId&gt;
              &lt;version&gt;${jackson.version}&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;com.fasterxml.jackson.module&lt;/groupId&gt;
              &lt;artifactId&gt;jackson-module-afterburner&lt;/artifactId&gt;
              &lt;version&gt;${jackson.afterburner.version}&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;com.github.arnabk&lt;/groupId&gt;
              &lt;artifactId&gt;java-dogstatsd-client&lt;/artifactId&gt;
              &lt;version&gt;1.0.1&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.json&lt;/groupId&gt;
              &lt;artifactId&gt;json&lt;/artifactId&gt;
              &lt;version&gt;20151123&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;javax.xml.bind&lt;/groupId&gt;
              &lt;artifactId&gt;jaxb-api&lt;/artifactId&gt;
              &lt;version&gt;2.2.11&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.im4java&lt;/groupId&gt;
              &lt;artifactId&gt;im4java&lt;/artifactId&gt;
              &lt;version&gt;1.4.0&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;
                  com.googlecode.maven-java-formatter-plugin
              &lt;/groupId&gt;
              &lt;artifactId&gt;maven-java-formatter-plugin&lt;/artifactId&gt;
              &lt;version&gt;0.4&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;mysql&lt;/groupId&gt;
              &lt;artifactId&gt;mysql-connector-java&lt;/artifactId&gt;
              &lt;version&gt;5.1.6&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;commons-dbcp&lt;/groupId&gt;
              &lt;artifactId&gt;commons-dbcp&lt;/artifactId&gt;
              &lt;version&gt;1.4&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.slf4j&lt;/groupId&gt;
              &lt;artifactId&gt;slf4j-api&lt;/artifactId&gt;
              &lt;version&gt;1.7.12&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.7.12&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;log4j&lt;/groupId&gt;
              &lt;artifactId&gt;log4j&lt;/artifactId&gt;
              &lt;version&gt;1.2.17&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;net.java.dev.jna&lt;/groupId&gt;
              &lt;artifactId&gt;jna&lt;/artifactId&gt;
              &lt;version&gt;4.2.2&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.apache.camel&lt;/groupId&gt;
              &lt;artifactId&gt;camel-jdbc&lt;/artifactId&gt;
              &lt;version&gt;${camel.version}&lt;/version&gt;
              &lt;scope&gt;provided&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.apache.camel&lt;/groupId&gt;
              &lt;artifactId&gt;camel-jetty&lt;/artifactId&gt;
              &lt;version&gt;${camel.version}&lt;/version&gt;
              &lt;scope&gt;provided&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.apache.camel&lt;/groupId&gt;
              &lt;artifactId&gt;camel-http4&lt;/artifactId&gt;
              &lt;version&gt;${camel.version}&lt;/version&gt;
              &lt;scope&gt;provided&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.apache.camel&lt;/groupId&gt;
              &lt;artifactId&gt;camel-aws&lt;/artifactId&gt;
              &lt;version&gt;${camel.version}&lt;/version&gt;
              &lt;scope&gt;provided&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.apache.camel&lt;/groupId&gt;
              &lt;artifactId&gt;camel-core&lt;/artifactId&gt;
              &lt;version&gt;${camel.version}&lt;/version&gt;
              &lt;scope&gt;provided&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.apache.camel&lt;/groupId&gt;
              &lt;artifactId&gt;camel-test&lt;/artifactId&gt;
              &lt;version&gt;${camel.version}&lt;/version&gt;
              &lt;scope&gt;test&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;com.github.tomakehurst&lt;/groupId&gt;
              &lt;artifactId&gt;wiremock&lt;/artifactId&gt;
              &lt;version&gt;1.58&lt;/version&gt;
              &lt;scope&gt;test&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;net.javacrumbs.json-unit&lt;/groupId&gt;
              &lt;artifactId&gt;json-unit&lt;/artifactId&gt;
              &lt;version&gt;1.11.0&lt;/version&gt;
              &lt;scope&gt;test&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;com.scireum&lt;/groupId&gt;
              &lt;artifactId&gt;s3ninja&lt;/artifactId&gt;
              &lt;version&gt;2.7&lt;/version&gt;
              &lt;scope&gt;test&lt;/scope&gt;
          &lt;/dependency&gt;
      &lt;/dependencies&gt;
  
      &lt;profiles&gt;
          &lt;profile&gt;
              &lt;activation&gt;
                  &lt;property&gt;
                      &lt;name&gt;!maven.test.skip&lt;/name&gt;
                  &lt;/property&gt;
              &lt;/activation&gt;
  
              &lt;build&gt;
                  &lt;resources&gt;
                      &lt;resource&gt;
                          &lt;directory&gt;src/main/resources&lt;/directory&gt;
                          &lt;excludes&gt;
                              &lt;exclude&gt;**/*.cfg&lt;/exclude&gt;
                          &lt;/excludes&gt;
                      &lt;/resource&gt;
                  &lt;/resources&gt;
                  &lt;testResources&gt;
                      &lt;testResource&gt;
                          &lt;directory&gt;${project.basedir}/src/test/resources/&lt;/directory&gt;
                      &lt;/testResource&gt;
                      &lt;testResource&gt;
                          &lt;directory&gt;${project.basedir}/src/test/resources/config/&lt;/directory&gt;
                      &lt;/testResource&gt;
                  &lt;/testResources&gt;
                  &lt;pluginManagement&gt;
                      &lt;plugins&gt;
                          &lt;plugin&gt;
                              &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
                              &lt;version&gt;3.3&lt;/version&gt;
                              &lt;configuration&gt;
                                  &lt;source&gt;1.8&lt;/source&gt;
                                  &lt;target&gt;1.8&lt;/target&gt;
                              &lt;/configuration&gt;
                          &lt;/plugin&gt;
                      &lt;/plugins&gt;
                  &lt;/pluginManagement&gt;
                  &lt;plugins&gt;
                      &lt;plugin&gt;
                          &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
                          &lt;artifactId&gt;maven-surefire-plugin&lt;/artifactId&gt;
                          &lt;version&gt;2.19.1&lt;/version&gt;
                          &lt;configuration&gt;
                              &lt;includes&gt;
                                  &lt;include&gt;${runSuite}&lt;/include&gt;
                              &lt;/includes&gt;
                              &lt;!-- &lt;skipTests&gt;true&lt;/skipTests&gt; --&gt;
                          &lt;/configuration&gt;
                      &lt;/plugin&gt;
                      &lt;plugin&gt;
                          &lt;groupId&gt;org.jacoco&lt;/groupId&gt;
                          &lt;artifactId&gt;jacoco-maven-plugin&lt;/artifactId&gt;
                          &lt;version&gt;0.7.0.201403182114&lt;/version&gt;
                          &lt;executions&gt;
                              &lt;execution&gt;
                                  &lt;goals&gt;
                                      &lt;goal&gt;prepare-agent&lt;/goal&gt;
                                  &lt;/goals&gt;
                              &lt;/execution&gt;
                          &lt;/executions&gt;
                          &lt;configuration&gt;
                              &lt;destFile&gt;${sonar.jacoco.reportPath}&lt;/destFile&gt;
                          &lt;/configuration&gt;
                      &lt;/plugin&gt;
                      &lt;!-- Documentation at https://karaf.apache.org/manual/latest/developers-guide/karaf-maven-plugin.html --&gt;
                      &lt;plugin&gt;
                          &lt;groupId&gt;org.apache.felix&lt;/groupId&gt;
                          &lt;artifactId&gt;maven-bundle-plugin&lt;/artifactId&gt;
                          &lt;version&gt;3.0.1&lt;/version&gt;
                          &lt;extensions&gt;true&lt;/extensions&gt;
                          &lt;configuration&gt;
                              &lt;instructions&gt;
                                  &lt;Bundle-SymbolicName&gt;${project.artifactId}&lt;/Bundle-SymbolicName&gt;
                                  &lt;Bundle-Description&gt;${project.description}&lt;/Bundle-Description&gt;
                                  &lt;Import-Package&gt;*;resolution:=optional&lt;/Import-Package&gt;
                              &lt;/instructions&gt;
                          &lt;/configuration&gt;
                      &lt;/plugin&gt;
                  &lt;/plugins&gt;
              &lt;/build&gt;
          &lt;/profile&gt;
      &lt;/profiles&gt;    
  &lt;/project&gt;
  </code></pre>
  
  <p>But setting log level to <code>ERROR</code> or some other value in <code>log4j.properties</code> is not making any effect. The actual level is always <code>INFO</code>. I have gone through this <a href="https://stackoverflow.com/questions/4106524/how-to-override-log4j-properties-during-testing">question</a> and tried modifying my sure-fire plugin configuration but still no luck.</p>
  
  <pre><code>&lt;plugin&gt;
      &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
      &lt;artifactId&gt;maven-surefire-plugin&lt;/artifactId&gt;
      &lt;version&gt;2.19.1&lt;/version&gt;
      &lt;configuration&gt;
          &lt;includes&gt;
              &lt;include&gt;${runSuite}&lt;/include&gt;
          &lt;/includes&gt;
          &lt;systemPropertyVariables&gt;
              &lt;log4j.configuration&gt;file:src/test/resources/log4j-surefire.properties&lt;/log4j.configuration&gt;
          &lt;/systemPropertyVariables&gt;
      &lt;/configuration&gt;
  &lt;/plugin&gt;
  </code></pre>
  
  <p>Maven version is as below:-</p>
  
  <pre><code>jabongs-MacBook-Pro-4:basecomponent debraj$ mvn -v
  Apache Maven 3.3.9 (bb52d8502b132ec0a5a3f4c09453c07478323dc5; 2015-11-10T22:11:47+05:30)
  Maven home: /Users/debraj/Downloads/apache-maven-3.3.9
  Java version: 1.8.0_77, vendor: Oracle Corporation
  Java home: /Library/Java/JavaVirtualMachines/jdk1.8.0_77.jdk/Contents/Home/jre
  Default locale: en_US, platform encoding: UTF-8
  OS name: "mac os x", version: "10.11.4", arch: "x86_64", family: "mac"
  </code></pre>
  
  <p>The issue is there only in test config and during the test execution. If the log level is changed in <code>src/main/resources/log4j.properties</code> then during the main application run the log level messages are fine.</p>
  
  <p>Can someone let me know what is going wrong?</p>