From bc8848be21e2a5399a2972cb7878af24dc3f4dfe Mon Sep 17 00:00:00 2001 From: Yongkoo Kang Date: Thu, 7 Dec 2023 10:13:37 -0800 Subject: [PATCH 1/3] Only load properties with the log4j prefix --- .../netflix/blitz4j/LoggingConfiguration.java | 26 ++++++++++++++----- 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/netflix/blitz4j/LoggingConfiguration.java b/src/main/java/com/netflix/blitz4j/LoggingConfiguration.java index d708fa9..8ce4a65 100644 --- a/src/main/java/com/netflix/blitz4j/LoggingConfiguration.java +++ b/src/main/java/com/netflix/blitz4j/LoggingConfiguration.java @@ -21,6 +21,8 @@ import java.net.URL; import java.util.Enumeration; import java.util.HashMap; +import java.util.Iterator; +import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.Properties; @@ -28,8 +30,10 @@ import java.util.concurrent.Executors; import java.util.concurrent.atomic.AtomicInteger; +import org.apache.commons.configuration.AbstractConfiguration; import org.apache.commons.configuration.ConfigurationConverter; import org.apache.commons.configuration.ConfigurationException; +import org.apache.commons.lang.StringUtils; import org.apache.log4j.LogManager; import org.apache.log4j.PropertyConfigurator; import org.apache.log4j.helpers.Loader; @@ -318,7 +322,19 @@ public synchronized void clearProperty(Object source, String name, Object value, * com.netflix.config.PropertyListener#configSourceLoaded(java.lang.Object) */ public void configSourceLoaded(Object source) { - Properties props = ConfigurationConverter.getProperties(ConfigurationManager.getConfigInstance()); + AbstractConfiguration config = ConfigurationManager.getConfigInstance(); + Properties props = new Properties(); + + char delimiter = config.getListDelimiter(); + + for (Iterator keys = config.getKeys(LOG4J_PREFIX); keys.hasNext();) { + String key = keys.next(); + List list = config.getList(key); + + // turn the list into a string + props.setProperty(key, StringUtils.join(list.iterator(), delimiter)); + } + reconfigure(props); } @@ -347,11 +363,9 @@ public synchronized void reconfigure(Properties props) { // set of original initialization properties Properties newOverrideProps = new Properties(); for (Entry prop : props.entrySet()) { - if (isLog4JProperty(prop.getKey().toString())) { - Object initialValue = initialProps.get(prop.getKey()); - if (initialValue == null || !initialValue.equals(prop.getValue())) { - newOverrideProps.put(prop.getKey(), prop.getValue()); - } + Object initialValue = initialProps.get(prop.getKey()); + if (initialValue == null || !initialValue.equals(prop.getValue())) { + newOverrideProps.put(prop.getKey(), prop.getValue()); } } From 6ccc6d350caa7ada45693c66d07fd2e51b794553 Mon Sep 17 00:00:00 2001 From: Yongkoo Kang Date: Thu, 7 Dec 2023 12:04:47 -0800 Subject: [PATCH 2/3] Update reconfigure javadoc --- src/main/java/com/netflix/blitz4j/LoggingConfiguration.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/netflix/blitz4j/LoggingConfiguration.java b/src/main/java/com/netflix/blitz4j/LoggingConfiguration.java index 8ce4a65..ff6261b 100644 --- a/src/main/java/com/netflix/blitz4j/LoggingConfiguration.java +++ b/src/main/java/com/netflix/blitz4j/LoggingConfiguration.java @@ -354,7 +354,8 @@ public synchronized void setProperty(Object source, String name, Object value, /** * Set a snapshot of all LOG4J properties and reconfigure if properties have been - * changed. + * changed. This assumes that the Properties being set here has already been filtered + * to only properties starting with LOG4J_PREFIX. * @param props Complete set of ALL log4j configuration properties including all * appenders and log level overrides */ From 52011761d35b774f6390eaa20b30ba2fa39dfac6 Mon Sep 17 00:00:00 2001 From: Yongkoo Kang Date: Thu, 7 Dec 2023 12:06:21 -0800 Subject: [PATCH 3/3] Remove unused import --- src/main/java/com/netflix/blitz4j/LoggingConfiguration.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/com/netflix/blitz4j/LoggingConfiguration.java b/src/main/java/com/netflix/blitz4j/LoggingConfiguration.java index ff6261b..7283e14 100644 --- a/src/main/java/com/netflix/blitz4j/LoggingConfiguration.java +++ b/src/main/java/com/netflix/blitz4j/LoggingConfiguration.java @@ -31,7 +31,6 @@ import java.util.concurrent.atomic.AtomicInteger; import org.apache.commons.configuration.AbstractConfiguration; -import org.apache.commons.configuration.ConfigurationConverter; import org.apache.commons.configuration.ConfigurationException; import org.apache.commons.lang.StringUtils; import org.apache.log4j.LogManager;