Skip to content

[main] Port InternalLoggerRegistry from 2.x (#3418 and #3681 ports)#4157

Merged
ramanathan1504 merged 5 commits into
apache:mainfrom
vpelikh:issue/3418-internal-logger-registry
Jul 20, 2026
Merged

[main] Port InternalLoggerRegistry from 2.x (#3418 and #3681 ports)#4157
ramanathan1504 merged 5 commits into
apache:mainfrom
vpelikh:issue/3418-internal-logger-registry

Conversation

@vpelikh

@vpelikh vpelikh commented Jun 26, 2026

Copy link
Copy Markdown

Port InternalLoggerRegistry from 2.x (#3418, #3681)

Minimizes lock usage by moving logger instantiation outside the write lock, preventing deadlocks that could occur when the logger constructor triggers property lookups or other pluggable operations (PR #3418, closes #3399).

Adds stale entry detection and removal via ReferenceQueue — when a Logger is garbage collected, its WeakReference is enqueued. Subsequent calls to getLogger(), computeIfAbsent(), or hasLogger() trigger expunging of stale entries, preventing memory leaks from accumulated dead entries (PR #3681).

Changes:

  • InternalLoggerRegistry — new multi-level WeakHashMap<MessageFactory, HashMap<String, WeakReference<Logger>>> structure with ReadWriteLock
  • LoggerContext.getLogger() — simplified to use registry.computeIfAbsent() (moves newLogger() outside the write lock)
  • InternalLoggerRegistryTest — 6 tests covering creation, lookup, and stale entry expunging (WeakReference + MessageFactory GC scenarios)

@vpelikh vpelikh changed the title [main] Port InternalLoggerRegistry from 2.x [main] Port InternalLoggerRegistry from 2.x (#3418 and #3681 port) Jun 26, 2026
@vpelikh vpelikh changed the title [main] Port InternalLoggerRegistry from 2.x (#3418 and #3681 port) [main] Port InternalLoggerRegistry from 2.x (#3418 and #3681) Jun 26, 2026
@vpelikh vpelikh mentioned this pull request Jun 26, 2026
27 tasks
Minimizes lock usage by moving logger instantiation outside the write lock (PR apache#3418). Adds stale entry detection via ReferenceQueue (PR apache#3681).

Signed-off-by: Vasily Pelikh <2010720+vpelikh@users.noreply.github.com>
@vpelikh
vpelikh force-pushed the issue/3418-internal-logger-registry branch from d4ae379 to 4d7dd8e Compare July 16, 2026 07:23
@vpelikh vpelikh changed the title [main] Port InternalLoggerRegistry from 2.x (#3418 and #3681) [main] Port InternalLoggerRegistry from 2.x (#3418 and #3681 ports) Jul 16, 2026
vpelikh and others added 3 commits July 16, 2026 14:42
…4j 3

InternalLoggerRegistry.getLogger(name, null) normalized null to a hardcoded ParameterizedMessageFactory.INSTANCE, but LoggerContext stored loggers under its DI-injected defaultMessageFactory (ReusableMessageFactory in Log4j 3). This store-key/get-key mismatch caused testGetLoggerRetrievesExistingLogger, testHasLoggerReturnsCorrectStatus, and testExpungeStaleWeakReferenceEntries to all fail.

- InternalLoggerRegistry: constructor-inject defaultMessageFactory (final field), resolve null→defaultMessageFactory instead of hardcoded INSTANCE.
- LoggerContext: construct InternalLoggerRegistry with its own defaultMessageFactory after DI resolution.
- Test: iterate all message-factory buckets (.values()) instead of assuming ParameterizedMessageFactory.INSTANCE.

@ramanathan1504 ramanathan1504 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM please proceed with comments is enough 👍🏾

@vpelikh
vpelikh requested a review from ramanathan1504 July 19, 2026 17:40
@ramanathan1504
ramanathan1504 enabled auto-merge (squash) July 20, 2026 15:58

@ramanathan1504 ramanathan1504 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

@ramanathan1504
ramanathan1504 merged commit 4dee591 into apache:main Jul 20, 2026
5 checks passed
@github-project-automation github-project-automation Bot moved this from Approved to Merged in Log4j pull request tracker Jul 20, 2026
@vpelikh
vpelikh deleted the issue/3418-internal-logger-registry branch July 20, 2026 16:12
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.

2 participants