title: Apache Log4j2 class-specific logging in a package using log4j2.xml
body: <p>I'm using log4j2 and I have a package containing lots of classes which follow a specific name-schema. I want all messages from all classes of a specific type in a corresponding log-file.</p>
  
  <p>The easiest way would be if Logger would support wildcards like this: <code>&lt;Logger name="de.gmxhome.golkonda.features.*Type1" ...&gt;</code>, but I learned, that log4j2 doesn't support that.</p>
  
  <p>I know, I can either name the loggers in class-files (e. g. all <code>*Type1</code>-classes as <code>public static final Logger LOGGER = LogManager.getLogger("Type1");</code>), or configure a separate logger for each class. But I do not want to change the code and since I'm dealing with many classes, the <code>log4j2.xml</code> would get very big. I was trying different filters, but could not get the right one.</p>
  
  <p>Is there a way to configure log4j2 to do that?</p>
  
  <p>Example: I have two classes</p>
  
  <pre><code>package de.gmxhome.golkonda.features;
  
  import org.apache.logging.log4j.LogManager;
  import org.apache.logging.log4j.Logger;
  
  public class Logger1 {
  
      public static final Logger LOGGER = LogManager.getLogger(Logger1.class);
  
      public static void log() {
          LOGGER.info("logger1");
      }
  }
  </code></pre>
  
  <p>Let's say, I have the same class named <code>public class Logger2</code> in the same package. The log-message should go in two appender:</p>
  
  <pre><code>
  
      &lt;Configuration status="WARN">
      &lt;Loggers>
  
          &lt;Properties>
              &lt;Property name="pattern">%d{DEFAULT} %-5level [%t] %c -
                  %m%n%xException{full}&lt;/Property>
          &lt;/Properties>
  
          &lt;Appenders>
              &lt;Console name="appenderLogger1" target="SYSTEM_OUT">
                  &lt;PatternLayout pattern="1: ${pattern}" />
              &lt;/Console>
              &lt;Console name="appenderLogger2" target="SYSTEM_OUT">
                  &lt;PatternLayout pattern="2: ${pattern}" />
              &lt;/Console>
          &lt;/Appenders>
  
              &lt;Logger name="de.gmxhome.golkonda.features" level="info" additivity="false">
                  &lt;AppenderRef ref="appenderLogger1" />
                  &lt;AppenderRef ref="appenderLogger2" />
              &lt;/Logger>
  
      &lt;/Loggers>
      &lt;/Configuration>
  
  </code></pre>
  
  <p>Is there a filter that can be applied on the appender for that purpose or is there another way to achieve this goal.</p>