Skip to content

Port MessageFactory-namespaced logger registry from 2.x - #4240

Open
vpelikh wants to merge 1 commit into
apache:mainfrom
vpelikh:GH-2962
Open

Port MessageFactory-namespaced logger registry from 2.x#4240
vpelikh wants to merge 1 commit into
apache:mainfrom
vpelikh:GH-2962

Conversation

@vpelikh

@vpelikh vpelikh commented Aug 4, 2026

Copy link
Copy Markdown

Summary

Completes the port of #2962 by removing the now-dead checkMessageFactory machinery from LoggerContext.
The MessageFactory-namespaced InternalLoggerRegistry itself was already ported in #4157. This PR removes the leftover core code that only existed to warn about message-factory mismatches under the old name-keyed registry.

Why checkMessageFactory was dead code

The LoggerRegistry now keys loggers by (name, message factory). As a result:

  • computeIfAbsent(name, mf, newLogger) always returns a logger whose message factory matches the requested one, so the warning branch !loggerMessageFactory.equals(messageFactory) could never fire.
  • getLogger normalizes a null message factory to the default before reaching the registry, so the null-mismatch branch was unreachable as well.

The behavior this method guarded against — returning an existing logger created with a different message factory — no longer exists: a request with a different factory now returns a distinct, correctly-bound logger instead of the old logger plus a warning. 2.x removed this dead method in PR #2936, the same change that introduced the namespaced registry there; this PR mirrors that change in the 3.x, keeping it a faithful port.

Note on registry placement: as suggested in #2962 (comment), the namespaced registry was kept out of log4j-api; it lives in log4j-core (mirroring 2.x) rather than log4j-kit, since kit sits below core and can't reference the core Logger type.

Changes

  1. log4j-coreLoggerContext
    • Removed private checkMessageFactory(ExtendedLogger, MessageFactory) and its call site in getLogger(String, MessageFactory).
    • Removed the now-unused ExtendedLogger and StatusLogger imports.
    • Added @Nullable to the message-factory parameter of getLogger(String, MessageFactory) and hasLogger(String, MessageFactory); refreshed the getLogger Javadoc to describe the message-factory-matching semantics.
  2. log4j-core-testLoggerTest
    • Added regression test getLogger_String_MessageFactoryMismatchProducesNoWarning: re-requests a logger with a different and with a null message factory, and asserts no "created with the message factory" status warning is emitted.
    • Kept the builder hardcoded source-line constant in sync with the file layout.

Closes #2962

The warning was dead code: `LoggerRegistry.computeIfAbsent` always returns a logger matching the requested message factory, so the mismatch condition could never fire after the message factory-namespaced registry port (apache#4157). Remove it and pin the behavior with a regression test asserting no warning is emitted when a logger is re-requested with a different message factory.
@vpelikh vpelikh changed the title Port MessageFactory-namespaced logger registry from 2.x (#2962) Port MessageFactory-namespaced logger registry from 2.x Aug 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

1 participant