jvz commented on issue #2116: URL: https://github.com/apache/logging-log4j2/issues/2116#issuecomment-1869804088
So I'm going to note that we're [removing the system properties for specifying classes](https://github.com/apache/logging-log4j2/issues/1977); you can currently register your own bundle class with a prioritized `ConfigurableInstanceFactoryPostProcessor` service class which can register the bindings ahead of time. In my `spi-cleanup` branch, I already separated the system properties bundle into its own bundle class that's registered before the default bundles class, though I'm working on removing the properties in general due to `ClassLoader` complexity. More documentation will be needed, but mimicking the existing code shouldn't be too tricky (just pick an integer less than `Integer.MAX_VALUE - 1000` such as, oh, `0`). Example of how to do this: ```java package com.example; import aQute.bnd.annotation.spi.ServiceProvider; import org.apache.logging.log4j.core.async.AsyncLoggerContextSelector; import org.apache.logging.log4j.core.selector.ContextSelector; import org.apache.logging.log4j.plugins.Ordered; import org.apache.logging.log4j.plugins.SingletonFactory; import org.apache.logging.log4j.plugins.di.ConfigurableInstanceFactory; import org.apache.logging.log4j.plugins.di.spi.ConfigurableInstanceFactoryPostProcessor; @Ordered(0) @ServiceProvider(ConfigurableInstanceFactoryPostProcessor.class) public class AsyncLoggerContextPostProcessor implements ConfigurableInstanceFactoryPostProcessor { @Override public void postProcessFactory(final ConfigurableInstanceFactory factory) { factory.registerBundle(new Object() { @SingletonFactory ContextSelector asyncContextSelector() { return factory.getInstance(AsyncLoggerContextSelector.class); } }); } } ``` If you're not using the same BND annotation processor thing, then instead of the `@ServiceProvider` annotation, you'll also need to add this class to either your `module-info.java` or to a `META-INF/services/org.apache.logging.log4j.plugins.di.spi.ConfigurableInstanceFactoryPostProcessor` file. The module info would be something like: ``` provides org.apache.logging.log4j.plugins.di.spi.ConfigurableInstanceFactoryPostProcessor with com.example.AsyncLoggerContextPostProcessor ``` In a future beta, I do have an easier way to register this, but it's not in beta1. However, this example will work without updates in future betas as the `Binding` class is going away in favor of a different DSL which supports scopes and dynamic bindings better. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
