Skip to content

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

Open
vpelikh wants to merge 3 commits into
apache:mainfrom
vpelikh:issue/3418-internal-logger-registry
Open

[main] Port InternalLoggerRegistry from 2.x (#3418 and #3681 ports)#4157
vpelikh wants to merge 3 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 added 2 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.
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