title: Route 3rd party libraries' Log4j logging to Log4j2
body: <p>My Java application which uses Log4j2 as its logging implementation has dependency on a 3rd party library which uses Log4j.</p>
  
  <p>I am trying to set root logger appender and log level programatically in my application (using code below) for these 3rd party loggers, but these 3rd party library's loggers are still not logging to myAppender:</p>
  
  <pre><code>LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
  LoggerConfig loggerConfig = ctx.getConfiguration().getLoggerConfig(
          LogManager.ROOT_LOGGER_NAME);
  loggerConfig.addAppender(myAppender, Level.ERROR, null);
  ctx.updateLoggers();
  </code></pre>
  
  <p>A solution I thought of was to use Log4jToSLF4JAdaptor to route log4j's logging to SLF4J and then use Log4JSLF4JImpl to route SLF4J's logging to my Log4J2 implementation but as stated here (<a href="https://logging.apache.org/log4j/2.0/log4j-slf4j-impl/index.html" rel="noreferrer">https://logging.apache.org/log4j/2.0/log4j-slf4j-impl/index.html</a>), it would lead to endless routing.</p>
  
  <p>Can you please suggest how can I route logging of these 3rd party library's loggers to myAppender ?</p>