title: Log4j logging in maven project
body: <p>I am running my Selenium Automation tests using <code>Maven</code>. From time of execution till end I see so many logs.</p>
  
  <p>I came to know with this code that only <code>.info</code> warnings and <code>.warn</code> goes to console and <code>.debug</code> doesn't.</p>
  
  <pre><code>public static void main(String[] args) {
          Logger log = LogManager.getLogger();
          log.debug("its a debug message");
          log.info("its a info message");
          log.warn("its a warning message");
      }
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>2015-12-24 13:58:21,166 ERROR Logger contains an invalid element or attribute "append"
  [INFO ] 2015-12-24 13:58:21.245 [main] DebuggerTest - its a info message
  [WARN ] 2015-12-24 13:58:21.247 [main] DebuggerTest - its a warning message
  </code></pre>
  
  <p>Now I want to pass on a variable in along with my <code>mvn</code> command that will switch on/off any logs in console.</p>
  
  <p>Something like: <code>mvn test --debugging -false</code> So that logs can be seen in generated logs file but not in console.</p>
  
  <p><strong>More info:</strong>
  I want something like given here:
  <a href="https://stackoverflow.com/questions/1140358/how-to-initialize-log4j-properly">How to initialize log4j properly?</a></p>
  
  <p>here user "MATH" advised to use :
  <code>Logger.getRootLogger().setLevel(Level.WARN);</code> if don't want to see debug logs </p>
  
  <p>I want to enable/disable this from <code>mvn</code> command line.</p>
  
  <p><strong>More info 2:</strong></p>
  
  <p>this is how my log4j2.xml looks:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;Configuration status="WARN"&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;PatternLayout pattern="[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n"/&gt;
          &lt;/Console&gt;
          &lt;RollingFile name="trace-log" fileName="${log-path}/rnf-info.log"
                       filePattern="${log-path}/rnf-trace-%d{yyyy-MM-dd}.log" append="false"&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;/Policies&gt;
          &lt;/RollingFile&gt;
          &lt;RollingFile name="debug-log" fileName="${log-path}/rnf-debug.log"
                       filePattern="${log-path}/rnf-debug-%d{yyyy-MM-dd}.log" append="false"&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;/Policies&gt;
          &lt;/RollingFile&gt;
      &lt;/Appenders&gt;
      &lt;Loggers&gt;
          &lt;Logger name="com.rnf" level="debug" additivity="false" append="false"&gt;
              &lt;appender-ref ref="trace-log" level="info"/&gt;
              &lt;appender-ref ref="debug-log" level="debug"/&gt;
          &lt;/Logger&gt;
          &lt;Root level="info" additivity="false"&gt;
              &lt;AppenderRef ref="console-log"/&gt;
          &lt;/Root&gt;
      &lt;/Loggers&gt;
  &lt;/Configuration&gt;
  </code></pre>