Skip to content
This repository has been archived by the owner on Dec 10, 2024. It is now read-only.

Only load properties with the log4j prefix #33

Merged
merged 3 commits into from
Dec 7, 2023
Merged
Changes from 1 commit
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
26 changes: 20 additions & 6 deletions src/main/java/com/netflix/blitz4j/LoggingConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,19 @@
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;
import java.util.concurrent.ExecutorService;
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;
Expand Down Expand Up @@ -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<String> keys = config.getKeys(LOG4J_PREFIX); keys.hasNext();) {
rgallardo-netflix marked this conversation as resolved.
Show resolved Hide resolved
String key = keys.next();
List<Object> list = config.getList(key);

// turn the list into a string
props.setProperty(key, StringUtils.join(list.iterator(), delimiter));
}

reconfigure(props);
}

Expand Down Expand Up @@ -347,11 +363,9 @@ public synchronized void reconfigure(Properties props) {
// set of original initialization properties
rgallardo-netflix marked this conversation as resolved.
Show resolved Hide resolved
Properties newOverrideProps = new Properties();
for (Entry<Object, Object> 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());
}
}

Expand Down
Loading