My Java application which uses Log4j2 as its logging implementation has dependency on a 3rd party library which uses Log4j.
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:
LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
LoggerConfig loggerConfig = ctx.getConfiguration().getLoggerConfig(
LogManager.ROOT_LOGGER_NAME);
loggerConfig.addAppender(myAppender, Level.ERROR, null);
ctx.updateLoggers();
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 (https://logging.apache.org/log4j/2.0/log4j-slf4j-impl/index.html), it would lead to endless routing.
Can you please suggest how can I route logging of these 3rd party library's loggers to myAppender ?