-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Centralize initialization in Provider
class
#2374
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have a feeling we can deliver a solution with less new public
methods/members, but... I am curious what you think.
log4j-api-test/src/test/java/org/apache/logging/log4j/spi/ThreadContextMapTest.java
Outdated
Show resolved
Hide resolved
log4j-api/src/main/java/org/apache/logging/log4j/spi/DefaultThreadContextMap.java
Show resolved
Hide resolved
log4j-api/src/main/java/org/apache/logging/log4j/spi/DefaultThreadContextMap.java
Outdated
Show resolved
Hide resolved
log4j-api/src/main/java/org/apache/logging/log4j/spi/Provider.java
Outdated
Show resolved
Hide resolved
log4j-api/src/main/java/org/apache/logging/log4j/spi/Provider.java
Outdated
Show resolved
Hide resolved
log4j-api/src/main/java/org/apache/logging/log4j/spi/Provider.java
Outdated
Show resolved
Hide resolved
log4j-api/src/main/java/org/apache/logging/log4j/spi/Provider.java
Outdated
Show resolved
Hide resolved
log4j-api/src/main/java/org/apache/logging/log4j/spi/Provider.java
Outdated
Show resolved
Hide resolved
log4j-api/src/main/java/org/apache/logging/log4j/spi/Provider.java
Outdated
Show resolved
Hide resolved
log4j-api/src/main/java/org/apache/logging/log4j/util/ProviderUtil.java
Outdated
Show resolved
Hide resolved
2b7448f
to
8c5ffb7
Compare
8c5ffb7
to
ed4c72e
Compare
We move the code responsible for the instantiation of `LoggerContextFactory` and `ThreadContextMap` from the static entry points to the logging system (`LogManager` and `ThreadContext`) to the `Provider` class. The `Provider` class is instantiated using `ServiceLoader`, so `log4j-core` 2.x and 3.x can reimplement the initialization process according to their own rules. E.g. `log4j-core` 3.x can use the DI to create an instance of `LoggerContextFactory` and `ThreadContextMap`. The following modification were performed: * a **new** system property `log4j.provider` was introduced, * the old `log4j2.loggerContextFactory` has been deprecated and revised: if set it selects the first provider that uses the given `LoggerContextFactory`. Therefore it selects now both the context factory and thread context map implementations, * private static configuration values were removed from `ThreadContextMap` implementations, helping test parallelisation, * a distinct `NoOpThreadContextStack` implementation has been introduced.
ed4c72e
to
3cfb7b5
Compare
I apologize for taking so long to look at this but while working on moving context related stuff to log4j-context-data I ran into this and it makes things much more difficult as it hard-wires a bunch of classes that should be internal/private into the Provider class. I would request that those changes be undone. |
Those internal/private classes are hardwired in Once I'll promote the
|
We move the code responsible for the instantiation of
LoggerContextFactory
andThreadContextMap
from the static entry points to the logging system (LogManager
andThreadContext
) to theProvider
class.The
Provider
class is instantiated usingServiceLoader
, solog4j-core
2.x and 3.x can reimplement the initialization process according to their own rules. E.g.log4j-core
3.x can use the DI to create an instance ofLoggerContextFactory
andThreadContextMap
.The following modification were performed:
log4j.provider
was introduced,log4j2.loggerContextFactory
has been deprecated and revised: if set it selects the first provider that uses the givenLoggerContextFactory
. Therefore it selects now both the context factory and thread context map implementations,ThreadContextMap
implementations, helping test parallelisation,NoOpThreadContextStack
implementation has been introduced.This PR only includes tests for the first two items. The remaining points should be covered by existing tests.