Repository navigation
Respect the logger-name hierarchy boundary in Configurator.setAllLevels and putIfAbsent results in AbstractConfiguration - #4419
Conversation
Configurator.setAllLevels(parentLogger, level) selected the child
LoggerConfigs with a plain startsWith, so setAllLevels("com.foo", TRACE)
also re-leveled the unrelated sibling loggers com.foobar and
com.foobar.child. Apply the same hierarchy-boundary check that
LoggerNameLevelRewritePolicy got in apache#4414: the parent itself, or names
that continue with a dot; the root logger and a trailing-dot parent
still cover everything below them.
Adds a LoggerTest case with a sibling logger that keeps its level, and
a changelog entry.
Signed-off-by: Sharang Gupta <sharang@sharanggupta.dev>
|
The boundary check matches #4414, and the sibling case fails without the fix. |
Give the child logger its own level in setAllLevelsDoesNotChangeSiblingLoggers, add a test for the root and trailing-dot parents, and shorten the changelog entry. Removing any one of the three checks now fails a test.
…on logger mutators addLoggerAppender attached an appender instance that was not registered when another appender with the same name already was, so the logger wrote to an instance the configuration never started or stopped. Attach the registered instance instead, respect the result of the loggerConfigs putIfAbsent in all three methods, and ignore null arguments in addLoggerFilter and setLoggerAdditive like addLoggerAppender does. Closes apache#3155
| setParents(); | ||
| logger.getContext().updateLoggers(); | ||
| } else { | ||
| existing.addAppender(effective, null, null); |
There was a problem hiding this comment.
This branch and the existing.addFilter(filter) and existing.setAdditive(additive) branches below have no test. Removing any of them keeps every test green. A LoggerConfig added with addLogger under a key that differs from its name reaches them, for example:
final LoggerConfig other = new LoggerConfig("other", Level.INFO, true);
config.addLogger("mismatch", other);
config.addLoggerFilter(context.getLogger("mismatch"), filter);
assertThat(other.hasFilter()).isTrue();| type="fixed"> | ||
| <issue id="3155" link="https://github.com/apache/logging-log4j2/issues/3155"/> | ||
| <description format="asciidoc"> | ||
| Fix `addLoggerAppender()` attaching an unregistered appender when its name is already registered, and `addLoggerFilter()`/`setLoggerAdditive()` failing on `null` arguments. |
There was a problem hiding this comment.
Can the entry be one short line with what the user sees?
| Fix `addLoggerAppender()` attaching an unregistered appender when its name is already registered, and `addLoggerFilter()`/`setLoggerAdditive()` failing on `null` arguments. | |
| Fix `Logger.addAppender()` attaching an unregistered appender. |
|
The setAllLevels tests now fail for each removed condition, and each new |
A LoggerConfig added under a key that differs from its name reaches the putIfAbsent branches of addLoggerAppender, addLoggerFilter and setLoggerAdditive, which no test covered.
Each putIfAbsent branch of addLoggerAppender, addLoggerFilter and setLoggerAdditive now fails exactly one test when removed.
Fixes #4418.
Fixes #3155.
Two independent
log4j-corefixes, in one PR as asked on #3155. The first two commits are the #4418 fix (unchanged since the review round), the third commit is the #3155 fix (previously #4423, closed).Configurator.setAllLevels(#4418)Configurator.setAllLevels(parentLogger, level)selected the childLoggerConfigs with a plainstartsWith, sosetAllLevels("com.foo", TRACE)also re-leveledcom.foobarandcom.foobar.child. This adds the same hierarchy-boundary check that #4414 introduced forLoggerNameLevelRewritePolicy(the parent itself, or names continuing with.; the root logger""and a trailing-dot parent still cover everything below them),LoggerTestcases that pin each boundary check (a sibling logger keeps its level; root and trailing-dot parents still reach their descendants), and a changelog entry.main(3.x) carries the identical lines inConfigurator.setAllLevels; happy to forward-port once this is merged.AbstractConfigurationlogger mutators (#3155)AbstractConfiguration.addLoggerAppender,addLoggerFilterandsetLoggerAdditive(the implementation behindcore.Logger#addAppender,#addFilterand#setAdditive) ignored the result of theirputIfAbsentcalls:addLoggerAppender: when a different appender instance was already registered under the same name, the new instance was not registered but was still attached to theLoggerConfig, so the logger wrote to an appender the configuration never started or stopped whilegetAppender(name)returned another one. The registered instance is now attached instead (first wins, asaddAppenderalready behaves), with a status-logger warning.loggerConfigs.putIfAbsent(loggerName, nlc)is respected; when a config already exists the change is applied to it instead of re-wiring the parents and updating the loggers again. Under the method lock and the exact-name lookup that precedes it this branch is defensive, so it has no test of its own.addLoggerFilterandsetLoggerAdditivenow ignorenullarguments likeaddLoggerAppenderdoes, instead of throwingNullPointerException(side note 1 in the issue).Tests, one per method in
AbstractConfigurationTest: the duplicate-name appender case; the filter case (null arguments ignored, exactly oneLoggerConfigcreated with the right parent, both filters applied); the additive case (null logger ignored, one config created, additivity reflected by the logger). All three fail before the change and pass after. Changelog entry for 2.x included.Checklist
2.x./mvnw verifyonlog4j-core/log4j-core-testwithLoggerTestandAbstractConfigurationTestsucceeds (spotless clean)src/changelog/.2.x.x, one per issue