Skip to content

Conversation

rjernst
Copy link
Member

@rjernst rjernst commented Oct 6, 2025

The bridge between Java util logging and Log4j works by mapping each log message received in JUL to a log event in log4j. The JUL bridge tests check that messages of varying log levels are emitted.

Unfortunately this has a bad interaction with entitlements and tests. When a class (eg Regex, used by the test mock logger) is loaded, entitlements looks at that class to see if it should transform it. It then logs a trace message to say it will not be transformed. Yet if a class is loaded late, like Regex is, entitlements will emit this trace log message while log4j is already appending the original test log message. That in turn causes a status log message indicating a recursive call to the mock appender, which tests do not expect, and the test fails.

This commit sidesteps the issue by adding a special prefix, jul, to the mapping between logger names in JUL and log4j. By not setting the log level of the root log4j logger, the entitlements trace message is never emitted.

The bridge between Java util logging and Log4j works by mapping each log
message received in JUL to a log event in log4j. The JUL bridge tests
check that messages of varying log levels are emitted.

Unfortunately this has a bad interaction with entitlements and tests.
When a class (eg Regex, used by the test mock logger) is loaded,
entitlements looks at that class to see if it should transform it. It
then logs a trace message to say it will not be transformed. Yet if a
class is loaded late, like Regex is, entitlements will emit this trace
log message while log4j is already appending the original test log
message. That in turn causes a status log message indicating a recursive
call to the mock appender, which tests do not expect, and the test
fails.

This commit sidesteps the issue by adding a special prefix, `jul`, to
the mapping between logger names in JUL and log4j. By not setting the
log level of the root log4j logger, the entitlements trace message is
never emitted.
@rjernst rjernst requested a review from a team as a code owner October 6, 2025 22:59
@rjernst rjernst added :Core/Infra/Logging Log management and logging utilities >refactoring :Core/Infra/Entitlements Entitlements infrastructure labels Oct 6, 2025
@elasticsearchmachine elasticsearchmachine added Team:Core/Infra Meta label for core/infra team v9.3.0 labels Oct 6, 2025
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-core-infra (Team:Core/Infra)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Core/Infra/Entitlements Entitlements infrastructure :Core/Infra/Logging Log management and logging utilities >refactoring Team:Core/Infra Meta label for core/infra team v9.3.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants