Deprecate externalContext and migrate to Map-backed getObject/putObject#4070
Deprecate externalContext and migrate to Map-backed getObject/putObject#4070ramanathan1504 wants to merge 5 commits into
Conversation
…on for web lookups
There was a problem hiding this comment.
Pull request overview
Fixes servlet context propagation for web lookups when Log4j is initialized with a composite configuration (comma-separated log4jConfiguration locations), ensuring ${web:*} lookups (notably ${web:servletContextName}) resolve consistently between single-file and composite modes.
Changes:
- Update
Log4jContextFactory#getContext(..., List<URI> configLocations, ...)to correctly handleexternalContextpassed as aMap.Entry<String, Object>by routing it through theContextSelectorentry-based overload. - Add a regression test that initializes Log4j via
Log4jWebLifeCycleusing a composite config and asserts${web:servletContextName}resolves.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| log4j-jakarta-web/src/test/java/org/apache/logging/log4j/web/WebLookupTest.java | Adds a regression test covering ${web:servletContextName} resolution for composite configuration initialization. |
| log4j-core/src/main/java/org/apache/logging/log4j/core/impl/Log4jContextFactory.java | Ensures Map.Entry external context is applied via the selector so web lookups can retrieve the ServletContext in composite mode. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…separated log4jConfiguration
…bject` for improved servlet context resolution in composite configurations
|
@ramanathan1504, I don't see any deprecations or whatsoever. What is the status of this PR? |
@vy, an update on my progress: I have completed the refactor to move to Map-based storage (putObject/getObject) and have applied the requested @deprecated annotations across log4j-api, log4j-core, and log4j-web. The full build mvn install is now successful. I am currently debugging a few remaining test failures in mvn verify to ensure all lookups and backward compatibility fallbacks are 100% correct. I will push the final fix shortly to resolve #2351 as discussed. |
This PR deprecates the externalContext methods in LoggerContext (API and Core) and replaces the internal storage with a ConcurrentHashMap accessible via putObject and getObject.
Key Changes:
1.Marked
setExternalContextandgetExternalContextas@Deprecated (since 2.27.0).2.Refactored
LoggerContextto use a Map-backed storage to prevent collisions between frameworks (e.g., Spring Boot and Log4j-Web).3.Maintained backward compatibility for Spring Boot by using a legacy key in the internal map.
Outcome:
This work resolves the servlet context resolution issue in composite configurations.
Fixes #2351