-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Add API to list supported configuration file extensions #3839
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
base: 2.x
Are you sure you want to change the base?
Conversation
Hi @ppkarwasz , Just a gentle reminder — PTAL when you have time. |
log4j-core/src/main/java/org/apache/logging/log4j/core/config/ConfigurationFactory.java
Outdated
Show resolved
Hide resolved
log4j-core/src/main/java/org/apache/logging/log4j/core/config/ConfigurationFactory.java
Outdated
Show resolved
Hide resolved
@ppkarwasz, would you mind reminding me why we decided to introduce a new API such that
Put another way, why don't we add a static |
Totally agree. Let’s put a default implementation in @Override
public List<String> getSupportedExtensions() {
final String[] types = getSupportedTypes(); // protected, legacy API
// Preserve legacy semantics: only advertise extensions when active and types are present.
return isActive() && types != null && types.length > 0
? Arrays.asList(types)
: Collections.emptyList();
}
I prefer the dedicated
|
Add getSupportedExtensions() methods to allow external frameworks like Spring Boot to determine which configuration file formats are currently supported at runtime. - Add abstract getSupportedExtensions() method to ConfigurationFactory - Implement getSupportedExtensions() in all ConfigurationFactory subclasses - Add comprehensive test closes apache#3775
Please don't – you will still end up having two methods doing the same thing.
Agreed. Let's make
What you're describing is not a problem, but a behavior and it is all good, AFAICT. It is up to the
That is a good idea.
|
Another concern I have regarding adding a new, as a matter of fact, 2nd after On Tuesday, in a meeting where @ppkarwasz and I were present, after hearing that one of the biggest Log4j users using programmatic configuration extensively, I am very reluctant to marry the concept of files with configurations. |
The inconsistency is in the way a factory communicates that it is inactive:
My point is that, as they are now implemented, it does not make sense to make these methods public.
I agree completely: a
I don’t think we should make either
Alternative proposalLooking again at If we take a step back, Spring Boot doesn’t actually need to know about multiple factories, or how we handle extensions and precedence. What it needs boils down to:
TL;DR: @yybmion, apologies that your PR turned into a broader discussion about |
Created #3896 for this.
I'm happy to see that the nudge by @yybmion helped us to avoid yet another peak of complexity. @ppkarwasz, thanks so much for your patience along this conversation and helping with evaluating alternatives. I liked your proposal on changing 1 I'm inclined to leave this PR as is for records, and implement the new |
My idea for the proposed method public Configuration getConfiguration(LoggerContext context, String name, List<URI> uris) is to encapsulate the logic currently in Lines 381 to 402 in 769b924
This would allow each One open question is how to define the nullability/return contract. The existing single-URI overload, public Configuration getConfiguration(LoggerContext context, String name, URI uri) has inconsistent behavior across implementations:
Most (but not all) callers explicitly check for |
@ppkarwasz @vy Thank you both for the incredibly thoughtful discussion and analysis! I really appreciate how this conversation evolved from my initial approach to a much deeper understanding of the underlying problem. Should I start working on this right away, or would you prefer to clarify a few implementation details first (like the nullability contract and specific behavior expectations)? |
@ppkarwasz, since there is no established default that one can claim as a stable API, I'm inclined to throw Will this new API necessitate an amendment/improvement to the manual? (I've skimmed through combined/composite configuration sections, but couldn't see any.)
@yybmion, please go ahead. I strongly advise you to work out the essentials first, and leave out the tests, docs, etc. Once we get it reviewed, you can continue with polishing the PR. |
I think the bigger issue is the nullability and return behavior, which is inconsistent across the existing public Configuration getConfiguration(LoggerContext ctx, ConfigurationSource source);
public Configuration getConfiguration(LoggerContext ctx, String name, URI location);
public Configuration getConfiguration(LoggerContext ctx, String name, URI location, ClassLoader loader);
That mix of My proposalReturn behavior
Parameter nullabilityFor arguments, I’d keep the current semantics and only be strict where it adds value:
This way we converge towards:
|
Summary
Add ConfigurationFactory.getActiveFileExtensions() and getSupportedExtensions() methods to allow external frameworks like Spring Boot to determine which configuration file formats are currently supported at runtime.
Example Usage
closes #3775
Checklist
Before we can review and merge your changes, please go through the checklist below. If you're still working on some items, feel free to submit your pull request as a draft—our CI will help guide you through the remaining steps.
✅ Required checks
License: I confirm that my changes are submitted under the Apache License, Version 2.0.
Commit signatures: All commits are signed and verifiable. (See GitHub Docs on Commit Signature Verification).
Code formatting: The code is formatted according to the project’s style guide.
How to check and fix formatting
./mvnw spotless:check
./mvnw spotless:apply
See the build instructions for details.
Build & Test: I verified that the project builds and all unit tests pass.
How to build the project
Run:
./mvnw verify
See the build instructions for details.
🧪 Tests (select one)
📝 Changelog (select one)
src/changelog/.2.x.x
. (See Changelog Entry File Guide).