title: How to use log4j2 with different log files?
body: <p>I have a log4j2.xml file that I configured as following:</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;${sys:catalina.base}/logs&lt;/Property&gt;
  &lt;/Properties&gt;
  &lt;Appenders&gt;
  
      &lt;!-- console appender --&gt;
      &lt;Console name="console-log" target="SYSTEM_OUT"&gt;
          &lt;PatternLayout pattern="[%-5level] %d{yyyy-MM-dd HH:mm:ss} [%t] %c{1} - %msg%n"/&gt;
      &lt;/Console&gt;
  
      &lt;!-- file appender --&gt;
      &lt;RollingFile name="commons-log" fileName="${log-path}/commons.log"
                   filePattern="${log-path}/commons-%d{yyyy-MM-dd}.log"&gt;
          &lt;!-- log pattern --&gt;
          &lt;PatternLayout&gt;
              &lt;pattern&gt;[%-5level] %d{yyyy-MM-dd HH:mm:ss} %c{1} - %msg%n&lt;/pattern&gt;
          &lt;/PatternLayout&gt;
  
          &lt;!-- set file size policy --&gt;
          &lt;Policies&gt;
              &lt;TimeBasedTriggeringPolicy /&gt;
              &lt;SizeBasedTriggeringPolicy size="5 MB" /&gt;
          &lt;/Policies&gt;
      &lt;/RollingFile&gt;
      &lt;RollingFile name="analytics-log" fileName="${log-path}/analytics.log"
                   filePattern="${log-path}/analytics-%d{yyyy-MM-dd}.log"&gt;
          &lt;PatternLayout&gt;
              &lt;pattern&gt;[%-5level] %d{yyyy-MM-dd HH:mm:ss} %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.test.app" level="debug" additivity="false"&gt;
          &lt;appender-ref ref="commons-log" level="debug"/&gt;
          &lt;appender-ref ref="analytics-log" level="warn"/&gt;
          &lt;appender-ref ref="console-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;
  </code></pre>
  
  <p></p>
  
  <p>Now, I want to custom log data into commons.log and analytics.log files.</p>
  
  <p>Example in java:</p>
  
  <pre><code>private static final Logger logCommon = LogManager.getLogger("commons-log");
  private static final Logger logAnalytics = LogManager.getLogger("analytics-log");
  </code></pre>
  
  <p>And I want to custom write log to each file when I need, example:</p>
  
  <pre><code>logCommons.info ("Need it save into commons.log file");
  logAnalytics.info ("Only save into analytics.log file");
  </code></pre>
  
  <p><strong>Question:</strong> How can I do that? Please help me fix all my issues from log4j2.xml file and in Java code examples.</p>
  
  <p>Thanks!</p>