Skip to content

Conversation

@ppkarwasz
Copy link
Contributor

@ppkarwasz ppkarwasz commented Mar 11, 2024

This commit ensures that:

  • an InstanceFactory is created in the Log4j Provider,
  • the same factory is injected as parameters to all the components of the chain Log4jContextFactory, ContextSelector, LoggerContext (child), Configuration (grand-child).
  • DI.createInstanceFactory is called only when strictly necessary.

Review kit

The most important changes are in log4j-core, log4j-async-logger:

  • ConfigurationFactory is split into an interface (ConfigurationFactory) and an abstract class (AbstractConfigurationFactory). The ConfigurationFactory type becomes an interface, which might be a non-acceptable change,
  • The entire tree Provider -> LoggerContextFactory -> ContextSelector -> LoggerContext -> Configuration is created using an InstanceFactory,
  • While it is impossible to eliminate the default constructors for DefaultConfiguration and NullConfiguration (the tests are filled with these), their usage is limited to tests,
  • LoggerConfig is refactored to require a Configuration parameter to retrieve the services it need (e.g. LogEventFactory),
  • The log4j-async-logger artifact has been refactored to create the necessary disruptors using the DI. Since the AsyncLoggerConfigDisruptor requires some configuration data only available in a Configuration, this forced a change in the way bundles of beans are registered with the DI: each child instance factory applies all available ConfigurableInstanceFactoryPostProcessor services to itself. Previously on the first instance factory did it.

The changes in log4j-api can probably be ignored: the end goal is to remove this artifact.

Part of #2290.

@ppkarwasz ppkarwasz requested a review from jvz March 11, 2024 21:17
@ppkarwasz ppkarwasz force-pushed the fix/generalize-di-usage branch from e0ba274 to 0c3b74b Compare March 14, 2024 20:00
This commit ensures that:

* an `InstanceFactory` is created in the Log4j `Provider`,
* the same factory is injected as parameters to all
  the components of the chain `Log4jContextFactory`, `ContextSelector`,
  `LoggerContext` (child), `Configuration` (grand-child).
* `DI.createInstanceFactory` is called only when strictly necessary.
@ppkarwasz ppkarwasz force-pushed the fix/generalize-di-usage branch from 0c3b74b to 68e22a7 Compare March 20, 2024 08:48
@ppkarwasz ppkarwasz merged commit 68e22a7 into feature/log4j-sdk Mar 20, 2024
@ppkarwasz ppkarwasz deleted the fix/generalize-di-usage branch March 20, 2024 14:33
@ppkarwasz
Copy link
Contributor Author

@jvz,

I am closing this as "partially reviewed", but I am waiting patiently to replace the 3 fully-fledged and configured InstanceFactorys with a nifty use of scopes.

@jvz
Copy link
Member

jvz commented Mar 21, 2024

Sounds good to me!

@ppkarwasz ppkarwasz mentioned this pull request Mar 28, 2024
8 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants