Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.apache.logging.log4j.core.LoggerContext;
import org.apache.logging.log4j.core.config.Configuration;
import org.apache.logging.log4j.core.config.LoggerConfig;
import org.apache.logging.log4j.core.config.Property;
import org.apache.logging.log4j.core.filter.ThresholdFilter;
import org.apache.logging.log4j.core.test.appender.ListAppender;
import org.apache.logging.log4j.core.test.junit.LoggerContextSource;
Expand All @@ -56,6 +57,21 @@ void testPropertiesConfiguration(final Configuration config) {
final Filter filter = config.getFilter();
assertNotNull(filter, "No Filter");
assertInstanceOf(ThresholdFilter.class, filter, "Not a Threshold Filter");

final List<Property> rootProperties = config.getRootLogger().getPropertyList();
assertNotNull(rootProperties, "Root properties list should not be null");
assertEquals(1, rootProperties.size());
assertEquals("client.address", rootProperties.get(0).getName());
assertEquals("${web:request.remoteAddress}", rootProperties.get(0).getValue());

final LoggerConfig log4jLogger = loggers.get("org.apache.logging.log4j");
assertNotNull(log4jLogger, "org.apache.logging.log4j logger should not be null");
final List<Property> log4jProperties = log4jLogger.getPropertyList();
assertNotNull(log4jProperties, "org.apache.logging.log4j properties list should not be null");
assertEquals(1, log4jProperties.size());
assertEquals("subsystem", log4jProperties.get(0).getName());
assertEquals("Database", log4jProperties.get(0).getValue());

final Logger logger = LogManager.getLogger(getClass());
logger.info("Welcome to Log4j!");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,11 @@ logger.log4j.additivity = false

rootLogger.appenderRef.console.ref = StdOut
rootLogger.level = ERROR

rootLogger.property.type = Property
rootLogger.property.name = client.address
rootLogger.property.value = $${web:request.remoteAddress}

logger.log4j.property.type = Property
logger.log4j.property.name = subsystem
logger.log4j.property.value = Database
Original file line number Diff line number Diff line change
Expand Up @@ -312,8 +312,9 @@ private LoggerComponentBuilder createLogger(final String key, final Properties p
}
if (levelAndRefs != null) {
loggerBuilder.addAttribute("levelAndRefs", levelAndRefs);
properties.remove("");
}
return loggerBuilder;
return processRemainingProperties(loggerBuilder, properties);
}

private RootLoggerComponentBuilder createRootLogger(final Properties properties) {
Expand Down Expand Up @@ -343,8 +344,10 @@ private RootLoggerComponentBuilder createRootLogger(final Properties properties)
addLoggersToComponent(loggerBuilder, properties);
if (levelAndRefs != null) {
loggerBuilder.addAttribute("levelAndRefs", levelAndRefs);
properties.remove("");
}
return addFiltersToComponent(loggerBuilder, properties);
addFiltersToComponent(loggerBuilder, properties);
return processRemainingProperties(loggerBuilder, properties);
}

private LayoutComponentBuilder createLayout(final String appenderName, final Properties properties) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<entry xmlns="https://logging.apache.org/xml/ns"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
https://logging.apache.org/xml/ns
https://logging.apache.org/xml/ns/log4j-changelog-0.xsd"
type="changed">
<issue id="4024" link="https://github.com/apache/logging-log4j2/issues/4024"/>
<issue id="4142" link="https://github.com/apache/logging-log4j2/pull/4142"/>
<description format="asciidoc">
Fix properties configuration format to correctly parse and apply nested custom properties on loggers and root loggers
</description>
</entry>
Loading