-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Move JCTools-based queues to a new log4j-jctools
module
#2104
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
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.
Nice job, looks good to me.
We might reevaluate the need for alternative recycler implementations in log4j-api
in the future, but for now I agree that log4j-core
is all we need.
I start to wonder how useful is it to fill log4j-api
with partial implementations. For example a recycled LogBuilder
is useful for log4j-core
, but not so much for log4j-to-slf4j
. If log4j-to-slf4j
is bound to Logback, the Log4j API builder will be recycled, but the underlying SLF4J builder won't. We might as well remove Recycler
from AbstractLogger
and move it into core.Logger
.
/** | ||
* Denotes the value to be used while sorting recycler factory providers to determine the precedence order. | ||
* Values will be sorted naturally, that is, lower values will imply higher precedence. | ||
* | ||
* @return the value to be used while sorting | ||
*/ | ||
default int getOrder() { | ||
return 100; | ||
} | ||
|
||
/** | ||
* The name of this recycler factory provider. | ||
* Recycler factory providers are required to have unique names. | ||
* | ||
* @return the name of this recycler factory provider | ||
*/ | ||
String getName(); |
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.
In the future we might consider using ServiceLoader.Provider<RecyclerFactory>
instead of this class and add an @Named
and @Order
annotation to the implementations of RecyclerFactory
. We already have a @Named
and @Order
annotation in log4j-core
and log4j-plugins
. @jvz, what do you think?
I could open an issue to explore this direction, although I don't have too much confidence in ServiceLoader#stream
, which is the only way to obtain ServiceLoader.Provider
instances: it is unable to skip faulty service implementations.
log4j-api/src/main/java/org/apache/logging/log4j/spi/recycler/package-info.java
Outdated
Show resolved
Hide resolved
...main/java/org/apache/logging/log4j/internal/recycler/ThreadLocalRecyclerFactoryProvider.java
Show resolved
Hide resolved
Co-authored-by: Piotr P. Karwasz <[email protected]>
|
This PR addresses #2075 by means of following changes:
ServiceProvider
slog4j-api
andlog4j-core
are removed in favor of a new module:log4j-jctools
Why does
log4j-jctools
depend onlog4j-core
?There are two places where JCTools is used as an optional dependency:
log4j-api
as aRecycler[Factory]
(used almost everywhere) implementationlog4j-core
as aBlockingQueueFactory
(used byAsyncAppender
inlog4j-core
) implementationThere are two approaches I can think of to remove the JCTools optional dependencies:
BlockingQueueFactory
fromlog4j-core
tolog4j-api
log4j-jctools
will only need to depend onlog4j-api
log4j-api
will be introduced a component that only matters for somelog4j-core
internallog4j-core
has access to plugins and hence, users were expected to provide custom@Configurable @Plugin BlockingQueueFactory
implementations that they can refer to inlog4j2.xml
. Though movingBlockingQueueFactory
tolog4j-api
will break this contract completely, sincelog4j-api
has no notion of plugins.log4j-jctools
depend onlog4j-core
and provide bothRecycler[Factory]
andBlockingQueueFactory
implementationslog4j-core
et al. (if there is such a use case at all) needs to manually excludelog4j-core
Review kit
o.a.l.log4j.internal.recycler
ando.a.l.log4j.spi
packages oflog4j-api
modulelog4j-core
log4j-jctools