title: log4j2 configuration not being applied when custom class loading
body: <p>I have a Java application (= launcher) which loads classes via a custom <a href="https://docs.oracle.com/javase/7/docs/api/java/lang/ClassLoader.html" rel="nofollow noreferrer">ClassLoader</a>. In my launched application as well as in the launcher I'm using <a href="https://logging.apache.org/log4j" rel="nofollow noreferrer"><code>log4j2</code></a> with a custom XML configuration.</p>
  <p>In the launcher:</p>
  <pre><code>private static final Logger LOGGER;
  
  static
  {
      loadLog4jConfiguration(ApplicationLauncherClient.class);
      LOGGER = getLogger();
  }
  </code></pre>
  <p><code>loadLog4jConfiguration()</code> is implemented as follows:</p>
  <pre><code>public static void loadLog4jConfiguration(final Class&lt;?&gt; clazz)
  {
      try
      {
          String resourceName = &quot;launcher-log4j2.xml&quot;;
          try (InputStream inputStream = clazz.getResourceAsStream(resourceName))
          {
              if (inputStream == null)
              {
                  System.err.println(&quot;Cannot find resource: &quot; + resourceName);
              } else
              {
                  ConfigurationSource configurationSource = new ConfigurationSource(inputStream);
                  Configurator.initialize(null, configurationSource);
              }
          }
      } catch (final Exception exception)
      {
          exception.printStackTrace();
      }
  }
  </code></pre>
  <p>In the launched application I do the same setup for <code>log4j2</code> but I load a *different* <code>log4j2.xml</code> file from the classpath (e.g. <a href="https://stackoverflow.com/questions/24005748">to provide <code>JTextArea</code> appending of log messages</a>).</p>
  <p>Unfortunately, the <code>JTextArea</code> logs do not work when custom classloading. They work however when I launch the application normally (e.g. via IDE). I assume there is some sort of clash between <code>log4j2</code> instances. The launcher and the launched application hold the <code>log4j2</code> maven dependency. How would I resolve this cleanly? I do not want to remove <code>log4j2</code> from the launcher entirely. I thought about maybe always passing a class instance into the <code>getLogger()</code> constructor on the launched application but that didn't help either. I printed out the <code>ClassLoader</code> of the <code>LOGGER</code> instance on the launched application and it said <code>sun.misc.Launcher$AppClassLoader</code> in both cases (when custom classloading and when launching it normally via the IDE) so now I'm not sure what else to try.</p>