Fix properties configuration support for per-logger properties#4142
Fix properties configuration support for per-logger properties#4142ramanathan1504 wants to merge 3 commits into
Conversation
…ustom levels, filters, and appenders
vy
left a comment
There was a problem hiding this comment.
.properties logger parsing drops leftover property.* keys because createLogger/createRootLogger do not pass remaining properties through processRemainingProperties. @ppkarwasz in #4024 suggests to forward remaining logger properties like appenders already do.
-
Blocker: the PR changes validation semantics. Existing code throws for missing appender/filter/logger essentials; the PR returns
nullinstead for appenders, filters, and loggers. That silently hides malformed configs and nested filters can still hitcomponentBuilder.add(createFilter(...))without a null check. This is unrelated to #4024. -
Blocker: the prefix-flattening logic is too heuristic. It scans for any
*.nameand rewrites the properties map increateAppender/createLogger. That can misinterpret nested component names as appender/logger names.partitionOnCommonPrefixesalready gives the right structure forlogger.foo.property.*, so this machinery should not be needed. -
Regression risk: named logger levels stop using
Strings.trimToNull; existing tests indicate trailing spaces on logger levels are intentional to support. -
Borrowable pieces: the test assertions checking
getRootLogger().getPropertyList()and named loggergetPropertyList()are useful. Also, the PR notices the empty""shorthand key must not be fed intoprocessRemainingProperties; I’d handle that locally withproperties.remove(""), not by changing the generic parser broadly.
I recommend to keep appender/filter parsing and validation unchanged; in createLogger and createRootLogger, consume the shorthand "" key, add refs/filters as today, then return processRemainingProperties(loggerBuilder, properties). Add focused tests for root logger properties, named logger properties, shorthand logger syntax, and preservation of malformed-config failures.
Fixes #4024
Summary
This PR fixes a bug where custom logger-level properties (e.g.,
logger.log4j.property.type = Property) were silently ignored and dropped when configuring Log4j 2 using a.propertiesfile.Changes
processRemainingPropertiesto recursively parse nested custom properties.createLoggerandcreateAppenderto correctly resolve names and flatten nested keys for dotted prefixes.nulland safely ignore invalid duplicate nameless configurations created by Log4j's dot-split prefix partitioning.processRemainingPropertiesto safely bypass empty property names ("") and added loops to clear processed"appenderRef"and"filter"keys to prevent duplicate parsing.Verification
PropertiesConfigurationTest#testPropertiesConfigurationto verify that custom properties are successfully loaded on both root and custom loggers.