title: Log4j configurations for debug and tests
body: <p>I want to have two Log4j config files in my web-application. 
  The first one I placed here: <em>conf/main/log4j.properties</em></p>
  
  <p>The second is here: <em>conf/test/resources/log4j-test.properties</em></p>
  
  <p>so my pom contains the following:</p>
  
  <pre><code>&lt;build&gt;....
      &lt;resources&gt;
          &lt;resource&gt;
              &lt;directory&gt;conf/main&lt;/directory&gt;
              &lt;filtering&gt;true&lt;/filtering&gt;
              &lt;includes&gt;
                  &lt;include&gt;*.properties&lt;/include&gt;
              &lt;/includes&gt;
          &lt;/resource&gt;
      &lt;/resources&gt;
      &lt;testResources&gt;
          &lt;testResource&gt;
              &lt;directory&gt;conf/test/resources&lt;/directory&gt;
              &lt;filtering&gt;true&lt;/filtering&gt;
              &lt;includes&gt;
                  &lt;include&gt;*.properties&lt;/include&gt;
              &lt;/includes&gt;
          &lt;/testResource&gt;
      &lt;/testResources&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.8.1&lt;/version&gt;
              &lt;configuration&gt;
                  &lt;systemPropertyVariables&gt;
                      &lt;log4j.configuration&gt;file:${project.build.testOutputDirectory}/log4j-test.properties&lt;/log4j.configuration&gt;
                  &lt;/systemPropertyVariables&gt;
              &lt;/configuration&gt;
          &lt;/plugin&gt;
          &lt;plugin&gt;
      .....
  </code></pre>
  
  <p>log4j.properties:</p>
  
  <pre><code>log4j.rootLogger=INFO, stdout, mainFile
  
  log4j.appender.stdout=org.apache.log4j.ConsoleAppender
  log4j.appender.stdout.Target=System.out
  log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
  log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
  
  log4j.appender.mainFile=org.apache.log4j.RollingFileAppender
  log4j.appender.mainFile.File=../logs/main.log
  log4j.appender.mainFile.MaxFileSize=1MB
  log4j.appender.mainFile.MaxBackupIndex=1
  log4j.appender.mainFile.layout=org.apache.log4j.PatternLayout
  log4j.appender.mainFile.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
  </code></pre>
  
  <p>and log4j-test.properties:</p>
  
  <pre><code>log4j.rootLogger=INFO, stdout
  
  log4j.appender.stdout=org.apache.log4j.ConsoleAppender
  log4j.appender.stdout.Target=System.out
  log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
  log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
  </code></pre>
  
  <p>My goal - to write logs from tests only to my console.
  For example I have a simple test method:</p>
  
  <pre><code>@Test(dataProvider = "invalidCredentials", threadPoolSize = 10, invocationCount = 1, invocationTimeOut = 1000)
  public void testGetUserByLoginInvalid(String login, String password) {
      LDAPUser user = LdapUtils.getUserByLogin(login, password);
      assertNull(user);
  } 
  </code></pre>
  
  <p>Class LdapUtils has logger definition: </p>
  
  <pre><code>private static final Logger logger = Logger.getLogger(LdapUtils.class);
  </code></pre>
  
  <p>and it can write some info-message: </p>
  
  <pre><code>public static LDAPUser getUserByLogin(String login, String password) {
      ....
      if (user == null) {
          logger.info(INVALID_USER + login);
          return null;
      }
      .....
  }
  </code></pre>
  
  <p>So the problem is: when I execute Maven install(or simply - test) it works fine because it reads log4j config from right place (conf/test/resources/log4j-test.properties) and writes nothing to file, only to console.</p>
  
  <p>But when I'm trying to run this test method in IntellijIDEA (righ click on testGetUserByLoginInvalid method and choose Run "testGetUserByLoginInvalid()" ) it fails with</p>
  
  <pre><code>log4j:ERROR setFile(null,true) call failed.
  java.io.FileNotFoundException: ..\logs\main.log (The system cannot find the path specified)
  </code></pre>
  
  <p>In this case it reads wrong config(log4j.properties instead of log4j-test.properties) and fails when trying to find ..\logs\main.log file </p>
  
  <p>log4j.appender.mainFile.File=../logs/main.log </p>
  
  <p>in case of web-application it seems to be just the same as</p>
  
  <p>log4j.appender.mainFile.File=${catalina.home}/logs/main.log</p>
  
  <p>But tests do not have to know something about ${catalina.home} at all, isn't it? Because they are not part of .war.   So my idea was to create its own log4j config for tests but I can't avoid this problem with reading wrong config when running test not with Maven but with IDEA as I've described above...</p>
  
  <p>Any idea's anyone? Or may be there's another way to do what I want?... Thank you very much in advance!</p>