Currently log4j2-android uses the log4j2.loggerContextFactory to register itself with the Log4j API. The usage of this property is deprecated since version 2.24.0 and will be removed in the future.
Please implement a Provider class and register it with ServiceLoader in a META-INF/services/org.apache.logging.log4j.spi.Provider class.
The Provider service determines both the LoggerContextFactory to use with the LogManager class and the ThreadContextMap to use with the ThreadContext class. Since the Android Log API does not handle context data, I would suggest to set the latter to NoOpThreadContextMap:
public class AndroidProvider extends Provider {
private static final LoggerContextFactory CONTEXT_FACTORY = new AndroidLoggerContextFactory();
public AndroidProvider() {
// Since this provider is targeted at Android,
// use a priority higher than those of the Log4j API implementations targeted at the JRE.
super(25, CURRENT_VERSION);
}
@Override
public LoggerContextFactory getLoggerContextFactory() {
return CONTEXT_FACTORY;
}
@Override
public ThreadContextMap getThreadContextMapInstance() {
// Android does not provide an MDC implementation
return NoOpThreadContextMap.INSTANCE;
}
}
Currently
log4j2-androiduses thelog4j2.loggerContextFactoryto register itself with the Log4j API. The usage of this property is deprecated since version2.24.0and will be removed in the future.Please implement a
Providerclass and register it withServiceLoaderin aMETA-INF/services/org.apache.logging.log4j.spi.Providerclass.The
Providerservice determines both theLoggerContextFactoryto use with theLogManagerclass and theThreadContextMapto use with theThreadContextclass. Since the Android Log API does not handle context data, I would suggest to set the latter toNoOpThreadContextMap: