Skip to content

Detect file collisions in SiftingAppender nested appenders (#1041) - #1056

Merged
ceki merged 1 commit into
qos-ch:masterfrom
seonwooj0810:fix/issue-1041-sifting-appender-file-collision
Jul 25, 2026
Merged

Detect file collisions in SiftingAppender nested appenders (#1041)#1056
ceki merged 1 commit into
qos-ch:masterfrom
seonwooj0810:fix/issue-1041-sifting-appender-file-collision

Conversation

@seonwooj0810

Copy link
Copy Markdown
Contributor

Fixes #1041

Root cause

FileCollisionAnalyser runs during the DEPENDENCY_ANALYSIS phase and only inspects statically declared FileAppender/RollingFileAppender models. A SiftingAppender instantiates its nested appender once per discriminator value at runtime, so the nested appender never passes through the static collision maps. When the nested file/fileNamePattern does not embed the discriminator key, every sifted instance resolves to the same target file and their output silently collides — exactly the case @ceki confirmed and scoped in the issue ("add an analyzer for the case the appender inside SiftingAppender does not make use of the discriminating key").

Change

When an AppenderModel contains a SiftModel, the analyser now:

  1. resolves the discriminator key from the model tree (<discriminator><Key>…</Key>),
  2. reads the nested appender's file/fileNamePattern raw body text (raw on purpose — the key is only bound as a substitution property at runtime), and
  3. if none of them reference ${<key>}, emits a warning naming the appender, the discriminator key, and the shared target file.

The check stays silent when the key cannot be determined from the configuration (e.g. a discriminator using a built-in default key) or when the nested appender writes to no file (e.g. a ConsoleAppender), to avoid false positives. It is a warning rather than a hard error/skip because the colliding appenders only exist at runtime and cannot be skipped at model-analysis time.

Change summary

  • FileCollisionAnalyser: detect the SiftingAppender variant and warn (SIFT_COLLISION_MESSAGE).
  • New tests + input configs.

Test evidence

Added to FileCollisionAnalyserTest:

  • siftingAppenderSharedFileIsDetected — nested <file> does not reference the discriminator key → warning is emitted (siftShared.xml, mirrors the issue's reproduction).
  • siftingAppenderDistinctFileIsNotFlagged — nested <file> embeds ${userId} → no warning (siftDistinct.xml).

Verification done: built logback-core, ran FileCollisionAnalyserTest (7/7 pass, incl. the 5 pre-existing collision tests) and the full *Sift* suite (14 run, 0 failures) — no regressions. JDK 21.

Automated tooling was used to help prepare this change; it has been reviewed and verified by a human.

FileCollisionAnalyser only inspects statically declared file/rolling-file
appenders during the DEPENDENCY_ANALYSIS phase. A SiftingAppender, however,
instantiates its nested appender once per discriminator value at runtime, so
that nested appender never passes through the static collision maps. As a
result two (or more) sifted appenders can silently write to the same file
when the nested file/fileNamePattern does not embed the discriminator key.

Add a dedicated check: when an AppenderModel contains a SiftModel, resolve
the discriminator key from the model tree and verify that the nested
appender's file/fileNamePattern textually references ${key}. If it does not,
every sifted appender resolves to the same target, so emit a warning naming
the appender, the discriminator key and the shared target file. The raw
(pre-substitution) body text is matched on purpose because the discriminator
key is only bound as a substitution property at runtime. When the key cannot
be determined from the configuration, or the nested appender writes to no
file, the check stays silent to avoid false positives.

Verification: new FileCollisionAnalyserTest cases siftShared.xml (nested
file does not reference the key -> warning) and siftDistinct.xml (nested
file embeds ${userId} -> no warning); the existing collision and sift test
suites still pass.

Signed-off-by: seonwoo_jung <79202163+seonwooj0810@users.noreply.github.com>
@ceki ceki self-assigned this Jul 25, 2026
@ceki ceki added this to the 1.6.1 milestone Jul 25, 2026
@ceki
ceki merged commit 15294cf into qos-ch:master Jul 25, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

File collision detection only happens during model analysis and misses runtime/dynamic appender collisions

2 participants