You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by rg...@apache.org on 2019/03/04 16:14:00 UTC
[logging-log4j2] 01/08: LOG4J2-913 - Access configurations by
HTTP/S. Support Spring Cloud Config
This is an automated email from the ASF dual-hosted git repository.
rgoers pushed a commit to branch LOG4J2-913
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git
commit a5c5987f31c5cff68a0828af64e828f97bc2614d
Author: Ralph Goers <rg...@apache.org>
AuthorDate: Thu Jan 24 20:41:26 2019 -0700
LOG4J2-913 - Access configurations by HTTP/S. Support Spring Cloud Config
LOG4J2-913 - App works with Cloud Config
LOG4j2-913 - Integration with Spring Cloud Config
---
.../apache/logging/log4j/util/PropertiesUtil.java | 15 ++
.../logging/log4j/util/PropertiesUtilTest.java | 15 +-
.../src/test/resources/log4j2.system.properties | 1 +
log4j-core/revapi.json | 5 +
.../log4j/core/config/AbstractConfiguration.java | 26 +++
.../log4j/core/config/ConfigurationFactory.java | 25 ++-
.../core/config/ConfigurationFileWatcher.java | 72 ++++++++
.../log4j/core/config/ConfigurationSource.java | 107 ++++++++++-
.../logging/log4j/core/config/HttpWatcher.java | 186 +++++++++++++++++++
.../config/builder/impl/BuiltConfiguration.java | 18 +-
.../builder/impl/DefaultConfigurationBuilder.java | 2 +-
.../config/composite/CompositeConfiguration.java | 24 +--
.../log4j/core/config/json/JsonConfiguration.java | 16 +-
.../log4j/core/config/xml/XmlConfiguration.java | 19 +-
.../log4j/core/net/ssl/SslConfiguration.java | 29 ++-
.../core/net/ssl/SslConfigurationFactory.java | 79 ++++++++
.../AbstractWatcher.java} | 42 ++++-
.../org/apache/logging/log4j/core/util/Source.java | 135 ++++++++++++++
.../logging/log4j/core/util/WatchManager.java | 152 +++++++++++----
.../apache/logging/log4j/core/util/Watcher.java | 78 ++++++++
.../logging/log4j/core/util/WatcherFactory.java | 89 +++++++++
.../log4j/core/util/WrappedFileWatcher.java | 90 +++++++++
.../logging/log4j/core/util/WatchHttpTest.java | 175 ++++++++++++++++++
.../src/test/resources/__files/log4j-test1.xml | 58 ++++++
.../log4j-spring-cloud-config-client/pom.xml | 196 ++++++++++++++++++++
.../client/Log4j2CloudConfigLoggingSystem.java | 127 +++++++++++++
.../src/main/resources/log4j2.system.properties | 1 +
.../log4j-spring-cloud-config-server/pom.xml | 205 +++++++++++++++++++++
.../server/controller/Log4jResourceController.java | 200 ++++++++++++++++++++
.../src/main/resources/META-INF/spring.factories | 1 +
log4j-spring-cloud-config/pom.xml | 95 ++++++++++
pom.xml | 1 +
32 files changed, 2175 insertions(+), 109 deletions(-)
diff --git a/log4j-api/src/main/java/org/apache/logging/log4j/util/PropertiesUtil.java b/log4j-api/src/main/java/org/apache/logging/log4j/util/PropertiesUtil.java
index c4104f7..4feb207 100644
--- a/log4j-api/src/main/java/org/apache/logging/log4j/util/PropertiesUtil.java
+++ b/log4j-api/src/main/java/org/apache/logging/log4j/util/PropertiesUtil.java
@@ -46,6 +46,8 @@ import java.util.concurrent.ConcurrentHashMap;
public final class PropertiesUtil {
private static final String LOG4J_PROPERTIES_FILE_NAME = "log4j2.component.properties";
+ private static final String LOG4J_SYSTEM_PROPERTIES_FILE_NAME = "log4j2.system.properties";
+ private static final String SYSTEM = "system:";
private static final PropertiesUtil LOG4J_PROPERTIES = new PropertiesUtil(LOG4J_PROPERTIES_FILE_NAME);
private final Environment environment;
@@ -315,6 +317,19 @@ public final class PropertiesUtil {
private final Map<List<CharSequence>, String> tokenized = new ConcurrentHashMap<>();
private Environment(final PropertySource propertySource) {
+ PropertyFilePropertySource sysProps = new PropertyFilePropertySource(LOG4J_SYSTEM_PROPERTIES_FILE_NAME);
+ try {
+ sysProps.forEach(new BiConsumer<String, String>() {
+ @Override
+ public void accept(String key, String value) {
+ if (System.getProperty(key) == null) {
+ System.setProperty(key, value);
+ }
+ }
+ });
+ } catch (SecurityException ex) {
+ // Access to System Properties is restricted so just skip it.
+ }
sources.add(propertySource);
for (final ClassLoader classLoader : LoaderUtil.getClassLoaders()) {
try {
diff --git a/log4j-api/src/test/java/org/apache/logging/log4j/util/PropertiesUtilTest.java b/log4j-api/src/test/java/org/apache/logging/log4j/util/PropertiesUtilTest.java
index 3ac9c92..a5dc873 100644
--- a/log4j-api/src/test/java/org/apache/logging/log4j/util/PropertiesUtilTest.java
+++ b/log4j-api/src/test/java/org/apache/logging/log4j/util/PropertiesUtilTest.java
@@ -17,14 +17,14 @@
package org.apache.logging.log4j.util;
-import org.junit.Before;
-import org.junit.Test;
-
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.Map;
import java.util.Properties;
+import org.junit.Before;
+import org.junit.Test;
+
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
@@ -108,4 +108,13 @@ public class PropertiesUtilTest {
System.getProperties().remove(key2);
}
}
+
+ @Test
+ public void testPublish() {
+ final Properties props = new Properties();
+ final PropertiesUtil util = new PropertiesUtil(props);
+ String value = System.getProperty("Application");
+ assertNotNull("System property was not published", value);
+ assertEquals("Log4j", value);
+ }
}
diff --git a/log4j-api/src/test/resources/log4j2.system.properties b/log4j-api/src/test/resources/log4j2.system.properties
new file mode 100644
index 0000000..6e4f8ae
--- /dev/null
+++ b/log4j-api/src/test/resources/log4j2.system.properties
@@ -0,0 +1 @@
+Application=Log4j
\ No newline at end of file
diff --git a/log4j-core/revapi.json b/log4j-core/revapi.json
index 9f6aef1..3c12553 100644
--- a/log4j-core/revapi.json
+++ b/log4j-core/revapi.json
@@ -31,6 +31,11 @@
"extension": "revapi.ignore",
"configuration": [
{
+ "code": "java.class.removed",
+ "old": "class org.apache.logging.log4j.core.config.ConfiguratonFileWatcher",
+ "justification": "LOG4J2-913 - This class name was misspelled"
+ },
+ {
"code": "java.method.returnTypeTypeParametersChanged",
"old": "method org.apache.logging.log4j.core.appender.AsyncAppender.Builder org.apache.logging.log4j.core.appender.AsyncAppender.Builder::setFilter(org.apache.logging.log4j.core.Filter)",
"new": "method B org.apache.logging.log4j.core.filter.AbstractFilterable.Builder<B extends org.apache.logging.log4j.core.filter.AbstractFilterable.Builder<B extends org.apache.logging.log4j.core.filter.AbstractFilterable.Builder<B>>>::setFilter(org.apache.logging.log4j.core.Filter) @ org.apache.logging.log4j.core.appender.AsyncAppender.Builder<B extends org.apache.logging.log4j.core.appender.AsyncAppender.Builder<B extends org.apache.logging.log4j.core.appender.AsyncAppender.Buil [...]
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/AbstractConfiguration.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/AbstractConfiguration.java
index ecaf4b3..de0d6eb 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/AbstractConfiguration.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/AbstractConfiguration.java
@@ -67,7 +67,10 @@ import org.apache.logging.log4j.core.util.DummyNanoClock;
import org.apache.logging.log4j.core.util.Loader;
import org.apache.logging.log4j.core.util.NameUtil;
import org.apache.logging.log4j.core.util.NanoClock;
+import org.apache.logging.log4j.core.util.Source;
import org.apache.logging.log4j.core.util.WatchManager;
+import org.apache.logging.log4j.core.util.Watcher;
+import org.apache.logging.log4j.core.util.WatcherFactory;
import org.apache.logging.log4j.util.PropertiesUtil;
/**
@@ -240,6 +243,29 @@ public abstract class AbstractConfiguration extends AbstractFilterable implement
LOGGER.debug("Configuration {} initialized", this);
}
+ protected void initializeWatchers(Reconfigurable reconfigurable, ConfigurationSource configSource,
+ int monitorIntervalSeconds) {
+ if ((configSource.getFile() != null || configSource.getURL() != null) && monitorIntervalSeconds > 0) {
+ watchManager.setIntervalSeconds(monitorIntervalSeconds);
+ if (configSource.getFile() != null) {
+ final Source cfgSource = new Source(configSource);
+ final long lastModifeid = configSource.getFile().lastModified();
+ final ConfigurationFileWatcher watcher = new ConfigurationFileWatcher(this, reconfigurable,
+ listeners, lastModifeid);
+ watchManager.watch(cfgSource, watcher);
+ } else if (configSource.getURL() != null) {
+ if (configSource.getLastModified() > 0) {
+ final Source cfgSource = new Source(configSource);
+ final Watcher watcher = WatcherFactory.getInstance(pluginPackages)
+ .newWatcher(cfgSource, this, reconfigurable, listeners, configSource.getLastModified());
+ watchManager.watch(cfgSource, watcher);
+ } else {
+ LOGGER.info("{} does not support dynamic reconfiguration", configSource.getURI());
+ }
+ }
+ }
+ }
+
/**
* Start the configuration.
*/
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/ConfigurationFactory.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/ConfigurationFactory.java
index 8c05959..f4adea0 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/ConfigurationFactory.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/ConfigurationFactory.java
@@ -21,6 +21,7 @@ import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.net.URI;
import java.net.URL;
+import java.net.URLConnection;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
@@ -29,6 +30,8 @@ import java.util.Map;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
+import javax.net.ssl.HttpsURLConnection;
+
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.core.LoggerContext;
@@ -38,6 +41,9 @@ import org.apache.logging.log4j.core.config.plugins.util.PluginManager;
import org.apache.logging.log4j.core.config.plugins.util.PluginType;
import org.apache.logging.log4j.core.lookup.Interpolator;
import org.apache.logging.log4j.core.lookup.StrSubstitutor;
+import org.apache.logging.log4j.core.net.ssl.LaxHostnameVerifier;
+import org.apache.logging.log4j.core.net.ssl.SslConfiguration;
+import org.apache.logging.log4j.core.net.ssl.SslConfigurationFactory;
import org.apache.logging.log4j.core.util.FileUtils;
import org.apache.logging.log4j.core.util.Loader;
import org.apache.logging.log4j.core.util.NetUtils;
@@ -128,6 +134,8 @@ public abstract class ConfigurationFactory extends ConfigurationBuilderFactory {
private static final Lock LOCK = new ReentrantLock();
+ private static final String HTTPS = "https";
+
/**
* Returns the ConfigurationFactory.
* @return the ConfigurationFactory.
@@ -294,7 +302,22 @@ public abstract class ConfigurationFactory extends ConfigurationBuilderFactory {
protected ConfigurationSource getInputFromString(final String config, final ClassLoader loader) {
try {
final URL url = new URL(config);
- return new ConfigurationSource(url.openStream(), FileUtils.fileFromUri(url.toURI()));
+ URLConnection urlConnection = url.openConnection();
+ if (url.getProtocol().equals(HTTPS)) {
+ SslConfiguration sslConfiguration = SslConfigurationFactory.getSslConfiguration();
+ if (sslConfiguration != null) {
+ ((HttpsURLConnection) urlConnection).setSSLSocketFactory(sslConfiguration.getSslSocketFactory());
+ if (!sslConfiguration.isVerifyHostName()) {
+ ((HttpsURLConnection) urlConnection).setHostnameVerifier(LaxHostnameVerifier.INSTANCE);
+ }
+ }
+ }
+ File file = FileUtils.fileFromUri(url.toURI());
+ if (file != null) {
+ return new ConfigurationSource(urlConnection.getInputStream(), FileUtils.fileFromUri(url.toURI()));
+ } else {
+ return new ConfigurationSource(urlConnection.getInputStream(), url, urlConnection.getLastModified());
+ }
} catch (final Exception ex) {
final ConfigurationSource source = ConfigurationSource.fromResource(config, loader);
if (source == null) {
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/ConfigurationFileWatcher.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/ConfigurationFileWatcher.java
new file mode 100644
index 0000000..e777fbf
--- /dev/null
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/ConfigurationFileWatcher.java
@@ -0,0 +1,72 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache license, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the license for the specific language governing permissions and
+ * limitations under the license.
+ */
+package org.apache.logging.log4j.core.config;
+
+import java.io.File;
+import java.util.List;
+
+import org.apache.logging.log4j.core.util.AbstractWatcher;
+import org.apache.logging.log4j.core.util.FileWatcher;
+import org.apache.logging.log4j.core.util.Source;
+import org.apache.logging.log4j.core.util.Watcher;
+
+/**
+ * Watcher for configuration files. Causes a reconfiguration when a file changes.
+ */
+public class ConfigurationFileWatcher extends AbstractWatcher implements FileWatcher {
+
+ private File file;
+ private long lastModifiedMillis;
+
+ public ConfigurationFileWatcher(final Configuration configuration, final Reconfigurable reconfigurable,
+ final List<ConfigurationListener> configurationListeners, long lastModifiedMillis) {
+ super(configuration, reconfigurable, configurationListeners);
+ this.lastModifiedMillis = lastModifiedMillis;
+ }
+
+ public long getLastModified() {
+ return file != null ? file.lastModified() : 0;
+ }
+
+ @Override
+ public void fileModified(final File file) {
+ lastModifiedMillis = file.lastModified();
+ }
+
+ @Override
+ public void watching(Source source) {
+ file = source.getFile();
+ lastModifiedMillis = file.lastModified();
+ super.watching(source);
+ }
+
+ @Override
+ public boolean isModified() {
+ return lastModifiedMillis != file.lastModified();
+ }
+
+ @Override
+ public Watcher newWatcher(final Reconfigurable reconfigurable, final List<ConfigurationListener> listeners,
+ long lastModifiedMillis) {
+ ConfigurationFileWatcher watcher = new ConfigurationFileWatcher(getConfiguration(), reconfigurable, listeners,
+ lastModifiedMillis);
+ if (getSource() != null) {
+ watcher.watching(getSource());
+ }
+ return watcher;
+ }
+}
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/ConfigurationSource.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/ConfigurationSource.java
index 21558fc..d7c1808 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/ConfigurationSource.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/ConfigurationSource.java
@@ -28,11 +28,18 @@ import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
+import java.net.URLConnection;
import java.util.Objects;
+import javax.net.ssl.HttpsURLConnection;
+
import org.apache.logging.log4j.Level;
+import org.apache.logging.log4j.core.net.ssl.LaxHostnameVerifier;
+import org.apache.logging.log4j.core.net.ssl.SslConfiguration;
+import org.apache.logging.log4j.core.net.ssl.SslConfigurationFactory;
import org.apache.logging.log4j.core.util.FileUtils;
import org.apache.logging.log4j.core.util.Loader;
+import org.apache.logging.log4j.core.util.Source;
import org.apache.logging.log4j.util.LoaderUtil;
/**
@@ -43,13 +50,18 @@ public class ConfigurationSource {
/**
* ConfigurationSource to use with Configurations that do not require a "real" configuration source.
*/
- public static final ConfigurationSource NULL_SOURCE = new ConfigurationSource(new byte[0]);
+ public static final ConfigurationSource NULL_SOURCE = new ConfigurationSource(new byte[0], null, 0);
+ private static final String HTTPS = "https";
private final File file;
private final URL url;
private final String location;
private final InputStream stream;
- private final byte[] data;
+ private volatile byte[] data;
+ private volatile Source source = null;
+ private final long lastModified;
+ // Set when the configuration has been updated so reset can use it for the next lastModified timestamp.
+ private volatile long modifiedMillis;
/**
* Constructs a new {@code ConfigurationSource} with the specified input stream that originated from the specified
@@ -64,6 +76,13 @@ public class ConfigurationSource {
this.location = file.getAbsolutePath();
this.url = null;
this.data = null;
+ long modified = 0;
+ try {
+ modified = file.lastModified();
+ } catch (Exception ex) {
+ // There is a problem with the file. It will be handled somewhere else.
+ }
+ this.lastModified = modified;
}
/**
@@ -79,6 +98,24 @@ public class ConfigurationSource {
this.location = url.toString();
this.file = null;
this.data = null;
+ this.lastModified = 0;
+ }
+
+ /**
+ * Constructs a new {@code ConfigurationSource} with the specified input stream that originated from the specified
+ * url.
+ *
+ * @param stream the input stream
+ * @param url the URL where the input stream originated
+ * @param lastModified when the source was last modified.
+ */
+ public ConfigurationSource(final InputStream stream, final URL url, long lastModified) {
+ this.stream = Objects.requireNonNull(stream, "stream is null");
+ this.url = Objects.requireNonNull(url, "URL is null");
+ this.location = url.toString();
+ this.file = null;
+ this.data = null;
+ this.lastModified = lastModified;
}
/**
@@ -89,15 +126,26 @@ public class ConfigurationSource {
* @throws IOException if an exception occurred reading from the specified stream
*/
public ConfigurationSource(final InputStream stream) throws IOException {
- this(toByteArray(stream));
+ this(toByteArray(stream), null, 0);
}
- private ConfigurationSource(final byte[] data) {
+ public ConfigurationSource(final Source source, final byte[] data, long lastModified) throws IOException {
+ Objects.requireNonNull(source, "source is null");
this.data = Objects.requireNonNull(data, "data is null");
this.stream = new ByteArrayInputStream(data);
+ this.file = source.getFile();
+ this.url = source.getURI().toURL();
+ this.location = source.getLocation();
+ this.lastModified = lastModified;
+ }
+
+ private ConfigurationSource(final byte[] data, final URL url, long lastModified) {
+ Objects.requireNonNull(data, "data is null");
+ this.stream = new ByteArrayInputStream(data);
this.file = null;
- this.url = null;
+ this.url = url;
this.location = null;
+ this.lastModified = lastModified;
}
/**
@@ -140,6 +188,18 @@ public class ConfigurationSource {
return url;
}
+ public void setSource(Source source) {
+ this.source = source;
+ }
+
+ public void setData(byte[] data) {
+ this.data = data;
+ }
+
+ public void setModifiedMillis(long modifiedMillis) {
+ this.modifiedMillis = modifiedMillis;
+ }
+
/**
* Returns a URI representing the configuration resource or null if it cannot be determined.
* @return The URI.
@@ -172,6 +232,14 @@ public class ConfigurationSource {
}
/**
+ * Returns the time the resource was last modified or 0 if it is not available.
+ * @return the last modified time of the resource.
+ */
+ public long getLastModified() {
+ return lastModified;
+ }
+
+ /**
* Returns a string describing the configuration source file or URL, or {@code null} if this configuration source
* has neither a file nor an URL.
*
@@ -197,13 +265,19 @@ public class ConfigurationSource {
* @throws IOException if a problem occurred while opening the new input stream
*/
public ConfigurationSource resetInputStream() throws IOException {
- if (file != null) {
+ if (source != null) {
+ return new ConfigurationSource(source, data, this.lastModified);
+ } else if (file != null) {
return new ConfigurationSource(new FileInputStream(file), file);
+ } else if (url != null && data != null) {
+ // Creates a ConfigurationSource without accessing the URL since the data was provided.
+ return new ConfigurationSource(data, url, modifiedMillis == 0 ? lastModified : modifiedMillis);
} else if (url != null) {
- return new ConfigurationSource(url.openStream(), url);
- } else {
- return new ConfigurationSource(data);
+ return fromUri(getURI());
+ } else if (data != null) {
+ return new ConfigurationSource(data, null, lastModified);
}
+ return null;
}
@Override
@@ -245,7 +319,20 @@ public class ConfigurationSource {
return null;
}
try {
- return new ConfigurationSource(configLocation.toURL().openStream(), configLocation.toURL());
+ URL url = configLocation.toURL();
+ URLConnection urlConnection = url.openConnection();
+ if (url.getProtocol().equals(HTTPS)) {
+ SslConfiguration sslConfiguration = SslConfigurationFactory.getSslConfiguration();
+ if (sslConfiguration != null) {
+ ((HttpsURLConnection) urlConnection).setSSLSocketFactory(sslConfiguration.getSslSocketFactory());
+ if (!sslConfiguration.isVerifyHostName()) {
+ ((HttpsURLConnection) urlConnection).setHostnameVerifier(LaxHostnameVerifier.INSTANCE);
+ }
+ }
+ }
+ InputStream is = urlConnection.getInputStream();
+ long lastModified = urlConnection.getLastModified();
+ return new ConfigurationSource(configLocation.toURL().openStream(), configLocation.toURL(), lastModified);
} catch (final MalformedURLException ex) {
ConfigurationFactory.LOGGER.error("Invalid URL {}", configLocation.toString(), ex);
} catch (final Exception ex) {
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/HttpWatcher.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/HttpWatcher.java
new file mode 100644
index 0000000..a2d1220
--- /dev/null
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/HttpWatcher.java
@@ -0,0 +1,186 @@
+/*
+ * Copyright (c) 2019 Nextiva, Inc. to Present.
+ * All rights reserved.
+ */
+package org.apache.logging.log4j.core.config;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.HttpURLConnection;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.List;
+import java.util.Properties;
+
+import javax.net.ssl.HttpsURLConnection;
+
+import org.apache.logging.log4j.Logger;
+import org.apache.logging.log4j.core.config.plugins.Plugin;
+import org.apache.logging.log4j.core.config.plugins.PluginAliases;
+import org.apache.logging.log4j.core.net.ssl.LaxHostnameVerifier;
+import org.apache.logging.log4j.core.net.ssl.SslConfiguration;
+import org.apache.logging.log4j.core.net.ssl.SslConfigurationFactory;
+import org.apache.logging.log4j.core.util.AbstractWatcher;
+import org.apache.logging.log4j.core.util.Source;
+import org.apache.logging.log4j.core.util.Watcher;
+import org.apache.logging.log4j.status.StatusLogger;
+import org.apache.logging.log4j.util.PropertiesUtil;
+
+/**
+ *
+ */
+@Plugin(name = "http", category = Watcher.CATEGORY, printObject = true)
+@PluginAliases("https")
+public class HttpWatcher extends AbstractWatcher {
+
+ private Logger LOGGER = StatusLogger.getLogger();
+
+ private static int DEFAULT_TIMEOUT = 60000;
+ private int connectTimeoutMillis = DEFAULT_TIMEOUT;
+ private int readTimeoutMillis = DEFAULT_TIMEOUT;
+ private SslConfiguration sslConfiguration;
+ private URL url;
+ private volatile long lastModifiedMillis;
+ private static final String JSON = "application/json";
+ private static final String XML = "application/xml";
+ private static final String PROPERTIES = "text/x-java-properties";
+ private static final String TEXT = "text/plain";
+ private static final int NOT_MODIFIED = 304;
+ private static final int OK = 200;
+ private static final int BUF_SIZE = 1024;
+ private static final String HTTP = "http";
+ private static final String HTTPS = "https";
+
+ public HttpWatcher(final Configuration configuration, final Reconfigurable reconfigurable,
+ final List<ConfigurationListener> configurationListeners, long lastModifiedMillis) {
+ super(configuration, reconfigurable, configurationListeners);
+ sslConfiguration = SslConfigurationFactory.getSslConfiguration();
+ this.lastModifiedMillis = lastModifiedMillis;
+ }
+
+ @Override
+ public long getLastModified() {
+ return lastModifiedMillis;
+ }
+
+ @Override
+ public boolean isModified() {
+ return refreshConfiguration();
+ }
+
+ @Override
+ public void watching(Source source) {
+ if (!source.getURI().getScheme().equals(HTTP) && !source.getURI().getScheme().equals(HTTPS)) {
+ throw new IllegalArgumentException("HttpWatcher requires a url using the HTTP or HTTPS protocol, not " +
+ source.getURI().getScheme());
+ }
+ try {
+ url = source.getURI().toURL();
+ } catch (MalformedURLException ex) {
+ throw new IllegalArgumentException("Invalid URL for HttpWatcher " + source.getURI(), ex);
+ }
+ super.watching(source);
+ }
+
+ @Override
+ public Watcher newWatcher(Reconfigurable reconfigurable, List<ConfigurationListener> listeners,
+ long lastModifiedMillis) {
+ HttpWatcher watcher = new HttpWatcher(getConfiguration(), reconfigurable, listeners, lastModifiedMillis);
+ if (getSource() != null) {
+ watcher.watching(getSource());
+ }
+ return watcher;
+ }
+
+ private boolean refreshConfiguration() {
+ try {
+ final HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
+ urlConnection.setAllowUserInteraction(false);
+ urlConnection.setDoOutput(true);
+ urlConnection.setDoInput(true);
+ urlConnection.setRequestMethod("GET");
+ if (connectTimeoutMillis > 0) {
+ urlConnection.setConnectTimeout(connectTimeoutMillis);
+ }
+ if (readTimeoutMillis > 0) {
+ urlConnection.setReadTimeout(readTimeoutMillis);
+ }
+ String[] fileParts = url.getFile().split("\\.");
+ String type = fileParts[fileParts.length - 1].trim();
+ String contentType = isXml(type) ? XML : isJson(type) ? JSON : isProperties(type) ? PROPERTIES : TEXT;
+ urlConnection.setRequestProperty("Content-Type", contentType);
+ urlConnection.setIfModifiedSince(lastModifiedMillis);
+ if (url.getProtocol().equals(HTTPS) && sslConfiguration != null) {
+ ((HttpsURLConnection) urlConnection).setSSLSocketFactory(sslConfiguration.getSslSocketFactory());
+ if (!sslConfiguration.isVerifyHostName()) {
+ ((HttpsURLConnection) urlConnection).setHostnameVerifier(LaxHostnameVerifier.INSTANCE);
+ }
+ }
+
+ urlConnection.connect();
+
+ try {
+ int code = urlConnection.getResponseCode();
+ switch (code) {
+ case NOT_MODIFIED: {
+ return false;
+ }
+ case OK: {
+ try (InputStream is = urlConnection.getInputStream()) {
+ ConfigurationSource configSource = getConfiguration().getConfigurationSource();
+ configSource.setData(readStream(is));
+ lastModifiedMillis = urlConnection.getLastModified();
+ configSource.setModifiedMillis(lastModifiedMillis);
+ LOGGER.debug("Content was modified for {}", url.toString());
+ return true;
+ } catch (final IOException e) {
+ try (InputStream es = urlConnection.getErrorStream()) {
+ LOGGER.info("Error accessing configuration at {}: {}", url,
+ readStream(es));
+ } catch (final IOException ioe) {
+ LOGGER.error("Error accessing configuration at {}: {}", url, e.getMessage());
+ }
+ return false;
+ }
+ }
+ default : {
+ if (code < 0) {
+ LOGGER.info("Invalid response code returned");
+ } else {
+ LOGGER.info("Unexpected response code returned {}", code);
+ }
+ return false;
+ }
+ }
+ } catch (final IOException ioe) {
+ LOGGER.error("Error accessing configuration at {}: {}", url, ioe.getMessage());
+ }
+ } catch (final IOException ioe) {
+ LOGGER.error("Error connecting to configuration at {}: {}", url, ioe.getMessage());
+ }
+ return false;
+ }
+
+ private byte[] readStream(InputStream is) throws IOException {
+ ByteArrayOutputStream result = new ByteArrayOutputStream();
+ byte[] buffer = new byte[BUF_SIZE];
+ int length;
+ while ((length = is.read(buffer)) != -1) {
+ result.write(buffer, 0, length);
+ }
+ return result.toByteArray();
+ }
+
+ private boolean isXml(String type) {
+ return type.equalsIgnoreCase("xml");
+ }
+
+ private boolean isJson(String type) {
+ return type.equalsIgnoreCase("json") || type.equalsIgnoreCase("jsn");
+ }
+
+ private boolean isProperties(String type) {
+ return type.equalsIgnoreCase("properties");
+ }
+}
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/builder/impl/BuiltConfiguration.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/builder/impl/BuiltConfiguration.java
index ae932ee..741859c 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/builder/impl/BuiltConfiguration.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/builder/impl/BuiltConfiguration.java
@@ -16,7 +16,6 @@
*/
package org.apache.logging.log4j.core.config.builder.impl;
-import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
@@ -25,7 +24,7 @@ import java.util.List;
import org.apache.logging.log4j.core.LoggerContext;
import org.apache.logging.log4j.core.config.AbstractConfiguration;
import org.apache.logging.log4j.core.config.ConfigurationSource;
-import org.apache.logging.log4j.core.config.ConfiguratonFileWatcher;
+import org.apache.logging.log4j.core.config.ConfigurationFileWatcher;
import org.apache.logging.log4j.core.config.Node;
import org.apache.logging.log4j.core.config.Reconfigurable;
import org.apache.logging.log4j.core.config.builder.api.Component;
@@ -35,6 +34,9 @@ import org.apache.logging.log4j.core.config.plugins.util.ResolverUtil;
import org.apache.logging.log4j.core.config.status.StatusConfiguration;
import org.apache.logging.log4j.core.util.FileWatcher;
import org.apache.logging.log4j.core.util.Patterns;
+import org.apache.logging.log4j.core.util.Source;
+import org.apache.logging.log4j.core.util.Watcher;
+import org.apache.logging.log4j.core.util.WatcherFactory;
/**
* This is the general version of the Configuration created by the Builder. It may be extended to
@@ -153,17 +155,7 @@ public class BuiltConfiguration extends AbstractConfiguration {
public void setMonitorInterval(final int intervalSeconds) {
if (this instanceof Reconfigurable && intervalSeconds > 0) {
- final ConfigurationSource configSource = getConfigurationSource();
- if (configSource != null) {
- final File configFile = configSource.getFile();
- if (intervalSeconds > 0) {
- getWatchManager().setIntervalSeconds(intervalSeconds);
- if (configFile != null) {
- final FileWatcher watcher = new ConfiguratonFileWatcher((Reconfigurable) this, listeners);
- getWatchManager().watchFile(configFile, watcher);
- }
- }
- }
+ initializeWatchers((Reconfigurable) this, getConfigurationSource(), intervalSeconds);
}
}
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/builder/impl/DefaultConfigurationBuilder.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/builder/impl/DefaultConfigurationBuilder.java
index c0595d7..0a6c2d1 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/builder/impl/DefaultConfigurationBuilder.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/builder/impl/DefaultConfigurationBuilder.java
@@ -170,7 +170,6 @@ public class DefaultConfigurationBuilder<T extends BuiltConfiguration> implement
}
final Constructor<T> constructor = clazz.getConstructor(LoggerContext.class, ConfigurationSource.class, Component.class);
configuration = constructor.newInstance(loggerContext, source, root);
- configuration.setMonitorInterval(monitorInterval);
configuration.getRootNode().getAttributes().putAll(root.getAttributes());
if (name != null) {
configuration.setName(name);
@@ -196,6 +195,7 @@ public class DefaultConfigurationBuilder<T extends BuiltConfiguration> implement
if (advertiser != null) {
configuration.createAdvertiser(advertiser, source);
}
+ configuration.setMonitorInterval(monitorInterval);
} catch (final Exception ex) {
throw new IllegalArgumentException("Invalid Configuration class specified", ex);
}
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/composite/CompositeConfiguration.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/composite/CompositeConfiguration.java
index 9b6b11a..2267639 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/composite/CompositeConfiguration.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/composite/CompositeConfiguration.java
@@ -29,7 +29,7 @@ import org.apache.logging.log4j.core.config.AbstractConfiguration;
import org.apache.logging.log4j.core.config.Configuration;
import org.apache.logging.log4j.core.config.ConfigurationFactory;
import org.apache.logging.log4j.core.config.ConfigurationSource;
-import org.apache.logging.log4j.core.config.ConfiguratonFileWatcher;
+import org.apache.logging.log4j.core.config.ConfigurationFileWatcher;
import org.apache.logging.log4j.core.config.Node;
import org.apache.logging.log4j.core.config.Reconfigurable;
import org.apache.logging.log4j.core.config.plugins.util.ResolverUtil;
@@ -37,7 +37,10 @@ import org.apache.logging.log4j.core.config.status.StatusConfiguration;
import org.apache.logging.log4j.core.util.FileWatcher;
import org.apache.logging.log4j.core.util.Loader;
import org.apache.logging.log4j.core.util.Patterns;
+import org.apache.logging.log4j.core.util.Source;
import org.apache.logging.log4j.core.util.WatchManager;
+import org.apache.logging.log4j.core.util.Watcher;
+import org.apache.logging.log4j.core.util.WatcherFactory;
import org.apache.logging.log4j.util.PropertiesUtil;
/**
@@ -106,14 +109,12 @@ public class CompositeConfiguration extends AbstractConfiguration implements Rec
staffChildConfiguration(targetConfiguration);
final WatchManager watchManager = getWatchManager();
final WatchManager targetWatchManager = targetConfiguration.getWatchManager();
- final FileWatcher fileWatcher = new ConfiguratonFileWatcher(this, listeners);
if (targetWatchManager.getIntervalSeconds() > 0) {
watchManager.setIntervalSeconds(targetWatchManager.getIntervalSeconds());
- final Map<File, FileWatcher> watchers = targetWatchManager.getWatchers();
- for (final Map.Entry<File, FileWatcher> entry : watchers.entrySet()) {
- if (entry.getValue() instanceof ConfiguratonFileWatcher) {
- watchManager.watchFile(entry.getKey(), fileWatcher);
- }
+ final Map<Source, Watcher> watchers = targetWatchManager.getConfigurationWatchers();
+ for (final Map.Entry<Source, Watcher> entry : watchers.entrySet()) {
+ watchManager.watch(entry.getKey(), entry.getValue().newWatcher(this, listeners,
+ entry.getValue().getLastModified()));
}
}
for (final AbstractConfiguration sourceConfiguration : configurations.subList(1, configurations.size())) {
@@ -132,11 +133,10 @@ public class CompositeConfiguration extends AbstractConfiguration implements Rec
watchManager.setIntervalSeconds(monitorInterval);
}
final WatchManager sourceWatchManager = sourceConfiguration.getWatchManager();
- final Map<File, FileWatcher> watchers = sourceWatchManager.getWatchers();
- for (final Map.Entry<File, FileWatcher> entry : watchers.entrySet()) {
- if (entry.getValue() instanceof ConfiguratonFileWatcher) {
- watchManager.watchFile(entry.getKey(), fileWatcher);
- }
+ final Map<Source, Watcher> watchers = sourceWatchManager.getConfigurationWatchers();
+ for (final Map.Entry<Source, Watcher> entry : watchers.entrySet()) {
+ watchManager.watch(entry.getKey(), entry.getValue().newWatcher(this, listeners,
+ entry.getValue().getLastModified()));
}
}
}
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/json/JsonConfiguration.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/json/JsonConfiguration.java
index 5b38dfb..c9d7162 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/json/JsonConfiguration.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/json/JsonConfiguration.java
@@ -33,7 +33,7 @@ import org.apache.logging.log4j.core.LoggerContext;
import org.apache.logging.log4j.core.config.AbstractConfiguration;
import org.apache.logging.log4j.core.config.Configuration;
import org.apache.logging.log4j.core.config.ConfigurationSource;
-import org.apache.logging.log4j.core.config.ConfiguratonFileWatcher;
+import org.apache.logging.log4j.core.config.ConfigurationFileWatcher;
import org.apache.logging.log4j.core.config.LoggerConfig;
import org.apache.logging.log4j.core.config.Node;
import org.apache.logging.log4j.core.config.Reconfigurable;
@@ -42,6 +42,9 @@ import org.apache.logging.log4j.core.config.plugins.util.ResolverUtil;
import org.apache.logging.log4j.core.config.status.StatusConfiguration;
import org.apache.logging.log4j.core.util.FileWatcher;
import org.apache.logging.log4j.core.util.Patterns;
+import org.apache.logging.log4j.core.util.Source;
+import org.apache.logging.log4j.core.util.Watcher;
+import org.apache.logging.log4j.core.util.WatcherFactory;
/**
* Creates a Node hierarchy from a JSON file.
@@ -70,6 +73,7 @@ public class JsonConfiguration extends AbstractConfiguration implements Reconfig
processAttributes(rootNode, root);
final StatusConfiguration statusConfig = new StatusConfiguration().withVerboseClasses(VERBOSE_CLASSES)
.withStatus(getDefaultStatus());
+ int monitorIntervalSeconds = 0;
for (final Map.Entry<String, String> entry : rootNode.getAttributes().entrySet()) {
final String key = entry.getKey();
final String value = getStrSubstitutor().replace(entry.getValue());
@@ -89,18 +93,12 @@ public class JsonConfiguration extends AbstractConfiguration implements Reconfig
} else if ("name".equalsIgnoreCase(key)) {
setName(value);
} else if ("monitorInterval".equalsIgnoreCase(key)) {
- final int intervalSeconds = Integer.parseInt(value);
- if (intervalSeconds > 0) {
- getWatchManager().setIntervalSeconds(intervalSeconds);
- if (configFile != null) {
- final FileWatcher watcher = new ConfiguratonFileWatcher(this, listeners);
- getWatchManager().watchFile(configFile, watcher);
- }
- }
+ monitorIntervalSeconds = Integer.parseInt(value);
} else if ("advertiser".equalsIgnoreCase(key)) {
createAdvertiser(value, configSource, buffer, "application/json");
}
}
+ initializeWatchers(this, configSource, monitorIntervalSeconds);
statusConfig.initialize();
if (getName() == null) {
setName(configSource.getLocation());
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/xml/XmlConfiguration.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/xml/XmlConfiguration.java
index 6b0e79a..0e5fa98 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/xml/XmlConfiguration.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/xml/XmlConfiguration.java
@@ -28,7 +28,6 @@ import javax.xml.XMLConstants;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.transform.Source;
import javax.xml.transform.stream.StreamSource;
import javax.xml.validation.Schema;
import javax.xml.validation.SchemaFactory;
@@ -38,7 +37,7 @@ import org.apache.logging.log4j.core.LoggerContext;
import org.apache.logging.log4j.core.config.AbstractConfiguration;
import org.apache.logging.log4j.core.config.Configuration;
import org.apache.logging.log4j.core.config.ConfigurationSource;
-import org.apache.logging.log4j.core.config.ConfiguratonFileWatcher;
+import org.apache.logging.log4j.core.config.ConfigurationFileWatcher;
import org.apache.logging.log4j.core.config.Node;
import org.apache.logging.log4j.core.config.Reconfigurable;
import org.apache.logging.log4j.core.config.plugins.util.PluginType;
@@ -48,7 +47,10 @@ import org.apache.logging.log4j.core.util.Closer;
import org.apache.logging.log4j.core.util.FileWatcher;
import org.apache.logging.log4j.core.util.Loader;
import org.apache.logging.log4j.core.util.Patterns;
+import org.apache.logging.log4j.core.util.Source;
import org.apache.logging.log4j.core.util.Throwables;
+import org.apache.logging.log4j.core.util.Watcher;
+import org.apache.logging.log4j.core.util.WatcherFactory;
import org.w3c.dom.Attr;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
@@ -110,6 +112,7 @@ public class XmlConfiguration extends AbstractConfiguration implements Reconfigu
final Map<String, String> attrs = processAttributes(rootNode, rootElement);
final StatusConfiguration statusConfig = new StatusConfiguration().withVerboseClasses(VERBOSE_CLASSES)
.withStatus(getDefaultStatus());
+ int monitorIntervalSeconds = 0;
for (final Map.Entry<String, String> entry : attrs.entrySet()) {
final String key = entry.getKey();
final String value = getStrSubstitutor().replace(entry.getValue());
@@ -132,18 +135,12 @@ public class XmlConfiguration extends AbstractConfiguration implements Reconfigu
} else if ("schema".equalsIgnoreCase(key)) {
schemaResource = value;
} else if ("monitorInterval".equalsIgnoreCase(key)) {
- final int intervalSeconds = Integer.parseInt(value);
- if (intervalSeconds > 0) {
- getWatchManager().setIntervalSeconds(intervalSeconds);
- if (configFile != null) {
- final FileWatcher watcher = new ConfiguratonFileWatcher(this, listeners);
- getWatchManager().watchFile(configFile, watcher);
- }
- }
+ monitorIntervalSeconds = Integer.parseInt(value);
} else if ("advertiser".equalsIgnoreCase(key)) {
createAdvertiser(value, configSource, buffer, "text/xml");
}
}
+ initializeWatchers(this, configSource, monitorIntervalSeconds);
statusConfig.initialize();
} catch (final SAXException | IOException | ParserConfigurationException e) {
LOGGER.error("Error parsing " + configSource.getLocation(), e);
@@ -151,7 +148,7 @@ public class XmlConfiguration extends AbstractConfiguration implements Reconfigu
if (strict && schemaResource != null && buffer != null) {
try (InputStream is = Loader.getResourceAsStream(schemaResource, XmlConfiguration.class.getClassLoader())) {
if (is != null) {
- final Source src = new StreamSource(is, LOG4J_XSD);
+ final javax.xml.transform.Source src = new StreamSource(is, LOG4J_XSD);
final SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
Schema schema = null;
try {
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/net/ssl/SslConfiguration.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/net/ssl/SslConfiguration.java
index 5603e89..5d341d6 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/net/ssl/SslConfiguration.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/net/ssl/SslConfiguration.java
@@ -46,13 +46,15 @@ public class SslConfiguration {
private final TrustStoreConfiguration trustStoreConfig;
private final SSLContext sslContext;
private final String protocol;
+ private final boolean verifyHostName;
private SslConfiguration(final String protocol, final KeyStoreConfiguration keyStoreConfig,
- final TrustStoreConfiguration trustStoreConfig) {
+ final TrustStoreConfiguration trustStoreConfig, boolean verifyHostName) {
this.keyStoreConfig = keyStoreConfig;
this.trustStoreConfig = trustStoreConfig;
this.protocol = protocol == null ? SslConfigurationDefaults.PROTOCOL : protocol;
this.sslContext = this.createSslContext();
+ this.verifyHostName = verifyHostName;
}
/**
@@ -232,7 +234,26 @@ public class SslConfiguration {
@PluginElement("KeyStore") final KeyStoreConfiguration keyStoreConfig,
@PluginElement("TrustStore") final TrustStoreConfiguration trustStoreConfig) {
// @formatter:on
- return new SslConfiguration(protocol, keyStoreConfig, trustStoreConfig);
+ return new SslConfiguration(protocol, keyStoreConfig, trustStoreConfig, false);
+ }
+
+ /**
+ * Creates an SslConfiguration from a KeyStoreConfiguration and a TrustStoreConfiguration.
+ *
+ * @param protocol The protocol, see http://docs.oracle.com/javase/7/docs/technotes/guides/security/StandardNames.html#SSLContext
+ * @param keyStoreConfig The KeyStoreConfiguration.
+ * @param trustStoreConfig The TrustStoreConfiguration.
+ * @return a new SslConfiguration
+ * @since 2.12
+ */
+ public static SslConfiguration createSSLConfiguration(
+ // @formatter:off
+ @PluginAttribute("protocol") final String protocol,
+ @PluginElement("KeyStore") final KeyStoreConfiguration keyStoreConfig,
+ @PluginElement("TrustStore") final TrustStoreConfiguration trustStoreConfig,
+ @PluginElement("verifyHostName") final boolean verifyHostName) {
+ // @formatter:on
+ return new SslConfiguration(protocol, keyStoreConfig, trustStoreConfig, verifyHostName);
}
@Override
@@ -304,4 +325,8 @@ public class SslConfiguration {
public String getProtocol() {
return protocol;
}
+
+ public boolean isVerifyHostName() {
+ return verifyHostName;
+ }
}
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/net/ssl/SslConfigurationFactory.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/net/ssl/SslConfigurationFactory.java
new file mode 100644
index 0000000..e3cc4d3
--- /dev/null
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/net/ssl/SslConfigurationFactory.java
@@ -0,0 +1,79 @@
+/*
+ * Copyright (c) 2019 Nextiva, Inc. to Present.
+ * All rights reserved.
+ */
+package org.apache.logging.log4j.core.net.ssl;
+
+import org.apache.logging.log4j.Logger;
+import org.apache.logging.log4j.status.StatusLogger;
+import org.apache.logging.log4j.util.PropertiesUtil;
+
+/**
+ * Creates an SSL configuration from Log4j properties.
+ */
+public class SslConfigurationFactory {
+
+ private static final Logger LOGGER = StatusLogger.getLogger();
+ private static SslConfiguration sslConfiguration = null;
+
+ private static final String trustStorelocation = "log4j2.trustStore.location";
+ private static final String trustStorePassword = "log4j2.trustStore.password";
+ private static final String trustStorePasswordFile = "log4j2.trustStore.passwordFile";
+ private static final String trustStorePasswordEnvVar = "log4j2.trustStore.passwordEnvironmentVariable";
+ private static final String trustStoreKeyStoreType = "log4j2.trustStore.keyStoreType";
+ private static final String trustStoreKeyManagerFactoryAlgorithm = "log4j2.trustStore.keyManagerFactoryAlgorithm";
+ private static final String keyStoreLocation = "log4j2.keyStore.location";
+ private static final String keyStorePassword = "log4j2.keyStorePassword";
+ private static final String keyStorePasswordFile = "log4j2.keyStorePasswordFile";
+ private static final String keyStorePasswordEnvVar = "log4j2.keyStorePasswordEnvironmentVariable";
+ private static final String keyStoreType = "log4j2.keyStore.type";
+ private static final String keyStoreKeyManagerFactoryAlgorithm = "log4j2.keyStore.keyManagerFactoryAlgorithm";
+ private static final String verifyHostName = "log4j2.ssl.verifyHostName";
+
+ static {
+ PropertiesUtil props = PropertiesUtil.getProperties();
+ KeyStoreConfiguration keyStoreConfiguration = null;
+ TrustStoreConfiguration trustStoreConfiguration = null;
+ String location = props.getStringProperty(trustStorelocation);
+ if (location != null) {
+ String password = props.getStringProperty(trustStorePassword);
+ char[] passwordChars = null;
+ if (password != null) {
+ passwordChars = password.toCharArray();
+ }
+ try {
+ trustStoreConfiguration = TrustStoreConfiguration.createKeyStoreConfiguration(location, passwordChars,
+ props.getStringProperty(trustStorePasswordEnvVar), props.getStringProperty(trustStorePasswordFile),
+ props.getStringProperty(trustStoreKeyStoreType), props.getStringProperty(trustStoreKeyManagerFactoryAlgorithm));
+ } catch (Exception ex) {
+ LOGGER.warn("Unable to create trust store configuration due to: {} {}", ex.getClass().getName(),
+ ex.getMessage());
+ }
+ }
+ location = props.getStringProperty(keyStoreLocation);
+ if (location != null) {
+ String password = props.getStringProperty(keyStorePassword);
+ char[] passwordChars = null;
+ if (password != null) {
+ passwordChars = password.toCharArray();
+ }
+ try {
+ keyStoreConfiguration = KeyStoreConfiguration.createKeyStoreConfiguration(location, passwordChars,
+ props.getStringProperty(keyStorePasswordEnvVar), props.getStringProperty(keyStorePasswordFile),
+ props.getStringProperty(keyStoreType), props.getStringProperty(keyStoreKeyManagerFactoryAlgorithm));
+ } catch (Exception ex) {
+ LOGGER.warn("Unable to create key store configuration due to: {} {}", ex.getClass().getName(),
+ ex.getMessage());
+ }
+ }
+ if (trustStoreConfiguration != null || keyStoreConfiguration != null) {
+ boolean isVerifyHostName = props.getBooleanProperty(verifyHostName, false);
+ sslConfiguration = SslConfiguration.createSSLConfiguration("https", keyStoreConfiguration,
+ trustStoreConfiguration, isVerifyHostName);
+ }
+ }
+
+ public static SslConfiguration getSslConfiguration() {
+ return sslConfiguration;
+ }
+}
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/ConfiguratonFileWatcher.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/util/AbstractWatcher.java
similarity index 65%
rename from log4j-core/src/main/java/org/apache/logging/log4j/core/config/ConfiguratonFileWatcher.java
rename to log4j-core/src/main/java/org/apache/logging/log4j/core/util/AbstractWatcher.java
index 38491f2..3dbb111 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/ConfiguratonFileWatcher.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/util/AbstractWatcher.java
@@ -14,46 +14,70 @@
* See the license for the specific language governing permissions and
* limitations under the license.
*/
-package org.apache.logging.log4j.core.config;
+package org.apache.logging.log4j.core.util;
import java.io.File;
import java.util.List;
-import org.apache.logging.log4j.core.util.FileWatcher;
-import org.apache.logging.log4j.core.util.Log4jThreadFactory;
+import org.apache.logging.log4j.core.config.Configuration;
+import org.apache.logging.log4j.core.config.ConfigurationListener;
+import org.apache.logging.log4j.core.config.Reconfigurable;
/**
* Watcher for configuration files. Causes a reconfiguration when a file changes.
*/
-public class ConfiguratonFileWatcher implements FileWatcher {
+public abstract class AbstractWatcher implements Watcher {
private final Reconfigurable reconfigurable;
private final List<ConfigurationListener> configurationListeners;
private final Log4jThreadFactory threadFactory;
+ private final Configuration configuration;
+ private Source source;
- public ConfiguratonFileWatcher(final Reconfigurable reconfigurable, final List<ConfigurationListener> configurationListeners) {
+ public AbstractWatcher(final Configuration configuration, final Reconfigurable reconfigurable,
+ final List<ConfigurationListener> configurationListeners) {
+ this.configuration = configuration;
this.reconfigurable = reconfigurable;
this.configurationListeners = configurationListeners;
- this.threadFactory = Log4jThreadFactory.createDaemonThreadFactory("ConfiguratonFileWatcher");
+ this.threadFactory = configurationListeners != null ?
+ Log4jThreadFactory.createDaemonThreadFactory("ConfiguratonFileWatcher") : null;
}
+ @Override
public List<ConfigurationListener> getListeners() {
return configurationListeners;
}
-
@Override
- public void fileModified(final File file) {
+ public void modified() {
for (final ConfigurationListener configurationListener : configurationListeners) {
final Thread thread = threadFactory.newThread(new ReconfigurationRunnable(configurationListener, reconfigurable));
thread.start();
}
}
+ public Configuration getConfiguration() {
+ return configuration;
+ }
+
+ public abstract long getLastModified();
+
+ public abstract boolean isModified();
+
+ @Override
+ public void watching(Source source) {
+ this.source = source;
+ }
+
+ @Override
+ public Source getSource() {
+ return source;
+ }
+
/**
* Helper class for triggering a reconfiguration in a background thread.
*/
- private static class ReconfigurationRunnable implements Runnable {
+ public static class ReconfigurationRunnable implements Runnable {
private final ConfigurationListener configurationListener;
private final Reconfigurable reconfigurable;
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/util/Source.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/util/Source.java
new file mode 100644
index 0000000..a0aa548
--- /dev/null
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/util/Source.java
@@ -0,0 +1,135 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache license, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the license for the specific language governing permissions and
+ * limitations under the license.
+ */
+
+package org.apache.logging.log4j.core.util;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.Objects;
+
+import org.apache.logging.log4j.Level;
+import org.apache.logging.log4j.core.config.ConfigurationFactory;
+import org.apache.logging.log4j.core.config.ConfigurationSource;
+import org.apache.logging.log4j.util.LoaderUtil;
+
+/**
+ * Represents the source for the logging configuration.
+ */
+public class Source {
+
+ /**
+ * Captures a URI or File.
+ */
+
+ private final File file;
+ private final URI uri;
+ private final String location;
+
+ /**
+ * Constructs a Source from a ConfigurationSource.
+ * @param source The ConfigurationSource.
+ */
+ public Source(ConfigurationSource source) {
+ this.file = source.getFile();
+ this.uri = source.getURI();
+ this.location = source.getLocation();
+ }
+
+ /**
+ * Constructs a new {@code Source} with the specified file.
+ * file.
+ *
+ * @param file the file where the input stream originated
+ */
+ public Source(final File file) {
+ this.file = Objects.requireNonNull(file, "file is null");
+ this.location = file.getAbsolutePath();
+ this.uri = null;
+ }
+
+ /**
+ * Constructs a new {@code Source} from the specified URI.
+ *
+ * @param uri the URL where the input stream originated
+ */
+ public Source(final URI uri, final long lastModified) {
+ this.uri = Objects.requireNonNull(uri, "URI is null");
+ this.location = uri.toString();
+ this.file = null;
+ }
+
+ /**
+ * Returns the file configuration source, or {@code null} if this configuration source is based on an URL or has
+ * neither a file nor an URL.
+ *
+ * @return the configuration source file, or {@code null}
+ */
+ public File getFile() {
+ return file;
+ }
+
+ /**
+ * Returns the configuration source URL, or {@code null} if this configuration source is based on a file or has
+ * neither a file nor an URL.
+ *
+ * @return the configuration source URL, or {@code null}
+ */
+ public URI getURI() {
+ return uri;
+ }
+
+ /**
+ * Returns a string describing the configuration source file or URL, or {@code null} if this configuration source
+ * has neither a file nor an URL.
+ *
+ * @return a string describing the configuration source file or URL, or {@code null}
+ */
+ public String getLocation() {
+ return location;
+ }
+
+ @Override
+ public String toString() {
+ return location;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (!(o instanceof Source)) {
+ return false;
+ }
+ Source source = (Source) o;
+ return Objects.equals(location, source.location);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(location);
+ }
+}
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/util/WatchManager.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/util/WatchManager.java
index 31a98ef..37e0a44 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/util/WatchManager.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/util/WatchManager.java
@@ -27,6 +27,7 @@ import java.util.concurrent.TimeUnit;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.core.AbstractLifeCycle;
+import org.apache.logging.log4j.core.config.ConfigurationFileWatcher;
import org.apache.logging.log4j.core.config.ConfigurationScheduler;
import org.apache.logging.log4j.status.StatusLogger;
@@ -39,7 +40,7 @@ import org.apache.logging.log4j.status.StatusLogger;
public class WatchManager extends AbstractLifeCycle {
private static Logger logger = StatusLogger.getLogger();
- private final ConcurrentMap<File, FileMonitor> watchers = new ConcurrentHashMap<>();
+ private final ConcurrentMap<Source, ConfigurationMonitor> watchers = new ConcurrentHashMap<>();
private int intervalSeconds = 0;
private ScheduledFuture<?> future;
private final ConfigurationScheduler scheduler;
@@ -60,8 +61,8 @@ public class WatchManager extends AbstractLifeCycle {
*/
public void reset() {
logger.debug("Resetting {}", this);
- for (final File file : watchers.keySet()) {
- reset(file);
+ for (final Source source: watchers.keySet()) {
+ reset(source);
}
}
@@ -81,16 +82,38 @@ public class WatchManager extends AbstractLifeCycle {
if (file == null) {
return;
}
- final FileMonitor fileMonitor = watchers.get(file);
- if (fileMonitor != null) {
- final long lastModifiedMillis = file.lastModified();
- if (lastModifiedMillis != fileMonitor.lastModifiedMillis) {
+ Source source = new Source(file);
+ reset(source);
+ }
+
+
+ /**
+ * Resets the configuration monitor for the given file being watched to its current last modified time. If this
+ * manager does not watch the given configuration, nothing happens.
+ * <p>
+ * This allows you to start, stop, reset and start again a manager, without triggering file modified events if the
+ * given watched configuration has changed during the period of time when the manager was stopped.
+ * </p>
+ *
+ * @param source
+ * the Source for the monitor to reset.
+ * @since 2.11.2
+ */
+ public void reset(final Source source) {
+ if (source == null) {
+ return;
+ }
+ final ConfigurationMonitor monitor = watchers.get(source);
+ if (monitor != null) {
+ Watcher watcher = monitor.getWatcher();
+ if (watcher.isModified()) {
+ final long lastModifiedMillis = watcher.getLastModified();
if (logger.isDebugEnabled()) {
- logger.debug("Resetting file monitor for '{}' from {} ({}) to {} ({})", file,
- millisToString(fileMonitor.lastModifiedMillis), fileMonitor.lastModifiedMillis,
- millisToString(lastModifiedMillis), lastModifiedMillis);
+ logger.debug("Resetting file monitor for '{}' from {} ({}) to {} ({})", source.getLocation(),
+ millisToString(monitor.lastModifiedMillis), monitor.lastModifiedMillis,
+ millisToString(lastModifiedMillis), lastModifiedMillis);
}
- fileMonitor.setLastModifiedMillis(lastModifiedMillis);
+ monitor.setLastModifiedMillis(lastModifiedMillis);
}
}
}
@@ -140,8 +163,20 @@ public class WatchManager extends AbstractLifeCycle {
* @since 2.11.0
*/
public void unwatchFile(final File file) {
- logger.debug("Unwatching file '{}'", file);
- watchers.remove(file);
+ Source source = new Source(file);
+ unwatch(source);
+ }
+
+ /**
+ * Unwatches the given file.
+ *
+ * @param source the Source to stop watching.
+ * the file to stop watching.
+ * @since 2.11.2
+ */
+ public void unwatch(final Source source) {
+ logger.debug("Unwatching configuration {}", source);
+ watchers.remove(source);
}
/**
@@ -149,21 +184,62 @@ public class WatchManager extends AbstractLifeCycle {
*
* @param file
* the file to watch.
+ * @param fileWatcher
+ * the watcher to notify of file changes.
+ */
+ public void watchFile(final File file, final FileWatcher fileWatcher) {
+ Watcher watcher;
+ if (fileWatcher instanceof Watcher) {
+ watcher = (Watcher) fileWatcher;
+ } else {
+ watcher = new WrappedFileWatcher(fileWatcher);
+ }
+ Source source = new Source(file);
+ watch(source, watcher);
+ }
+
+ /**
+ * Watches the given file.
+ *
+ * @param source the source to watch.
* @param watcher
* the watcher to notify of file changes.
*/
- public void watchFile(final File file, final FileWatcher watcher) {
- final long lastModified = file.lastModified();
+ public void watch(final Source source, final Watcher watcher) {
+ watcher.watching(source);
+ final long lastModified = watcher.getLastModified();
if (logger.isDebugEnabled()) {
- logger.debug("Watching file '{}' for lastModified {} ({})", file, millisToString(lastModified), lastModified);
+ logger.debug("Watching configuration '{}' for lastModified {} ({})", source, millisToString(lastModified), lastModified);
}
- watchers.put(file, new FileMonitor(lastModified, watcher));
+ watchers.put(source, new ConfigurationMonitor(lastModified, watcher));
}
+ /**
+ * Returns a Map of the file watchers.
+ * @return A Map of the file watchers.
+ * @deprecated use getConfigurationWatchers.
+ */
public Map<File, FileWatcher> getWatchers() {
final Map<File, FileWatcher> map = new HashMap<>(watchers.size());
- for (final Map.Entry<File, FileMonitor> entry : watchers.entrySet()) {
- map.put(entry.getKey(), entry.getValue().fileWatcher);
+ for (Map.Entry<Source, ConfigurationMonitor> entry : watchers.entrySet()) {
+ if (entry.getValue().getWatcher() instanceof ConfigurationFileWatcher) {
+ map.put(entry.getKey().getFile(), (FileWatcher) entry.getValue().getWatcher());
+ } else {
+ map.put(entry.getKey().getFile(), new WrappedFileWatcher((FileWatcher)entry.getValue().getWatcher()));
+ }
+ }
+ return map;
+ }
+
+ /**
+ * Return the ConfigurationWaatchers.
+ * @return the ConfigurationWatchers.
+ * @since 2.11.2
+ */
+ public Map<Source, Watcher> getConfigurationWatchers() {
+ final Map<Source, Watcher> map = new HashMap<>(watchers.size());
+ for (final Map.Entry<Source, ConfigurationMonitor> entry : watchers.entrySet()) {
+ map.put(entry.getKey(), entry.getValue().getWatcher());
}
return map;
}
@@ -180,34 +256,34 @@ public class WatchManager extends AbstractLifeCycle {
@Override
public void run() {
logger.trace("{} run triggered.", SIMPLE_NAME);
- for (final Map.Entry<File, FileMonitor> entry : watchers.entrySet()) {
- final File file = entry.getKey();
- final FileMonitor fileMonitor = entry.getValue();
- final long lastModfied = file.lastModified();
- if (fileModified(fileMonitor, lastModfied)) {
+ for (final Map.Entry<Source, ConfigurationMonitor> entry : watchers.entrySet()) {
+ final Source source = entry.getKey();
+ final ConfigurationMonitor monitor = entry.getValue();
+ if (monitor.getWatcher().isModified()) {
+ final long lastModified = monitor.getWatcher().getLastModified();
if (logger.isInfoEnabled()) {
- logger.info("File '{}' was modified on {} ({}), previous modification was on {} ({})", file,
- millisToString(lastModfied), lastModfied, millisToString(fileMonitor.lastModifiedMillis),
- fileMonitor.lastModifiedMillis);
+ logger.info("Source '{}' was modified on {} ({}), previous modification was on {} ({})", source,
+ millisToString(lastModified), lastModified, millisToString(monitor.lastModifiedMillis),
+ monitor.lastModifiedMillis);
}
- fileMonitor.lastModifiedMillis = lastModfied;
- fileMonitor.fileWatcher.fileModified(file);
+ monitor.lastModifiedMillis = lastModified;
+ monitor.getWatcher().modified();
}
}
logger.trace("{} run ended.", SIMPLE_NAME);
}
-
- private boolean fileModified(final FileMonitor fileMonitor, final long lastModifiedMillis) {
- return lastModifiedMillis != fileMonitor.lastModifiedMillis;
- }
}
- private final class FileMonitor {
- private final FileWatcher fileWatcher;
+ private final class ConfigurationMonitor {
+ private final Watcher watcher;
private volatile long lastModifiedMillis;
- public FileMonitor(final long lastModifiedMillis, final FileWatcher fileWatcher) {
- this.fileWatcher = fileWatcher;
+ public Watcher getWatcher() {
+ return watcher;
+ }
+
+ public ConfigurationMonitor(final long lastModifiedMillis, final Watcher watcher) {
+ this.watcher = watcher;
this.lastModifiedMillis = lastModifiedMillis;
}
@@ -217,7 +293,7 @@ public class WatchManager extends AbstractLifeCycle {
@Override
public String toString() {
- return "FileMonitor [fileWatcher=" + fileWatcher + ", lastModifiedMillis=" + lastModifiedMillis + "]";
+ return "ConfigurationMonitor [watcher=" + watcher + ", lastModifiedMillis=" + lastModifiedMillis + "]";
}
}
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/util/Watcher.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/util/Watcher.java
new file mode 100644
index 0000000..7ae9cd0
--- /dev/null
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/util/Watcher.java
@@ -0,0 +1,78 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache license, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the license for the specific language governing permissions and
+ * limitations under the license.
+ */
+package org.apache.logging.log4j.core.util;
+
+import java.util.List;
+
+import org.apache.logging.log4j.core.config.Configuration;
+import org.apache.logging.log4j.core.config.ConfigurationListener;
+import org.apache.logging.log4j.core.config.Reconfigurable;
+
+/**
+ * Watches for changes in a Source and performs an action when it is modified.
+ *
+ * @see WatchManager
+ */
+public interface Watcher {
+
+ public static final String CATEGORY = "Watcher";
+
+ /**
+ * Returns the list of listeners for this configuration.
+ * @return The list of listeners.
+ */
+ List<ConfigurationListener> getListeners();
+
+ /**
+ * Called when the configuration has been modified.
+ * @param source The location of the configuration that was modified.
+ */
+ void modified();
+
+ /**
+ * Periodically called to determine if the configuration has been modified.
+ * @return true if the configuration was modified, false otherwise.
+ */
+ boolean isModified();
+
+ /**
+ * Returns the time the source was last modified or 0 if it is not available.
+ * @return the time the soruce was last modified.
+ */
+ long getLastModified();
+
+ /**
+ * Called when the Watcher is registered.
+ * @param source the Source that is being watched.
+ */
+ void watching(Source source);
+
+ /**
+ * Returns the Source being monitored.
+ * @return the Source.
+ */
+ Source getSource();
+
+ /**
+ * Creates a new Watcher by copying the original and using the new Reconfigurable and listeners.
+ * @param reconfigurable The Reconfigurable.
+ * @param listeners the listeners.
+ * @param lastModifiedMillis The time the resource was last modified in milliseconds.
+ * @return A new Watcher.
+ */
+ Watcher newWatcher(Reconfigurable reconfigurable, List<ConfigurationListener> listeners, long lastModifiedMillis);
+}
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/util/WatcherFactory.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/util/WatcherFactory.java
new file mode 100644
index 0000000..ab9e86c
--- /dev/null
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/util/WatcherFactory.java
@@ -0,0 +1,89 @@
+/*
+ * Copyright (c) 2019 Nextiva, Inc. to Present.
+ * All rights reserved.
+ */
+package org.apache.logging.log4j.core.util;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+
+import org.apache.logging.log4j.Logger;
+import org.apache.logging.log4j.core.config.Configuration;
+import org.apache.logging.log4j.core.config.ConfigurationFileWatcher;
+import org.apache.logging.log4j.core.config.ConfigurationListener;
+import org.apache.logging.log4j.core.config.Reconfigurable;
+import org.apache.logging.log4j.core.config.plugins.util.PluginManager;
+import org.apache.logging.log4j.core.config.plugins.util.PluginType;
+import org.apache.logging.log4j.status.StatusLogger;
+
+/**
+ * Creates Watchers of various types.
+ */
+public class WatcherFactory {
+
+ private static Logger LOGGER = StatusLogger.getLogger();
+ private static PluginManager pluginManager = new PluginManager(Watcher.CATEGORY);
+
+ private static volatile WatcherFactory factory = null;
+
+ private final Map<String, PluginType<?>> plugins;
+
+ private WatcherFactory(List<String> packages) {
+ pluginManager.collectPlugins(packages);
+ plugins = pluginManager.getPlugins();
+ }
+
+ public static WatcherFactory getInstance(List<String> packages) {
+ if (factory == null) {
+ synchronized(pluginManager) {
+ if (factory == null) {
+ factory = new WatcherFactory(packages);
+ }
+ }
+ }
+ return factory;
+ }
+
+ @SuppressWarnings("unchecked")
+ public Watcher newWatcher(Source source, final Configuration configuration, final Reconfigurable reconfigurable,
+ final List<ConfigurationListener> configurationListeners, long lastModifiedMillis) {
+ if (source.getFile() != null) {
+ return new ConfigurationFileWatcher(configuration, reconfigurable, configurationListeners,
+ lastModifiedMillis);
+ } else {
+ String name = source.getURI().getScheme();
+ PluginType<?> pluginType = plugins.get(name);
+ if (pluginType != null) {
+ return instantiate(name, (Class<? extends Watcher>) pluginType.getPluginClass(),
+ configuration, reconfigurable, configurationListeners, lastModifiedMillis);
+ }
+ LOGGER.info("No Watcher plugin is available for protocol '{}'", name);
+ return null;
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ public static <T extends Watcher> T instantiate(String name, final Class<T> clazz, final Configuration configuration,
+ final Reconfigurable reconfigurable, final List<ConfigurationListener> listeners, long lastModifiedMillis) {
+ Objects.requireNonNull(clazz, "No class provided");
+ try {
+ Constructor constructor = clazz.getConstructor(Configuration.class, Reconfigurable.class, List.class, long.class);
+ return (T) constructor.newInstance(configuration, reconfigurable, listeners, lastModifiedMillis);
+ } catch (NoSuchMethodException ex) {
+ throw new IllegalArgumentException("No valid constructor for Watcher plugin " + name, ex);
+ } catch (final LinkageError | InstantiationException e) {
+ // LOG4J2-1051
+ // On platforms like Google App Engine and Android, some JRE classes are not supported: JMX, JNDI, etc.
+ throw new IllegalArgumentException(e);
+ } catch (final IllegalAccessException e) {
+ throw new IllegalStateException(e);
+ } catch (final InvocationTargetException e) {
+ Throwables.rethrow(e.getCause());
+ throw new InternalError("Unreachable");
+ }
+ }
+}
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/util/WrappedFileWatcher.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/util/WrappedFileWatcher.java
new file mode 100644
index 0000000..ffab8bb
--- /dev/null
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/util/WrappedFileWatcher.java
@@ -0,0 +1,90 @@
+/*
+ * Copyright (c) 2019 Nextiva, Inc. to Present.
+ * All rights reserved.
+ */
+package org.apache.logging.log4j.core.util;
+
+import java.io.File;
+import java.util.Collections;
+import java.util.List;
+
+import org.apache.logging.log4j.core.config.Configuration;
+import org.apache.logging.log4j.core.config.ConfigurationListener;
+import org.apache.logging.log4j.core.config.Reconfigurable;
+
+/**
+ *
+ */
+public class WrappedFileWatcher extends AbstractWatcher implements FileWatcher {
+
+ private final FileWatcher watcher;
+ private volatile long lastModifiedMillis;
+
+ public WrappedFileWatcher(FileWatcher watcher, final Configuration configuration,
+ final Reconfigurable reconfigurable, final List<ConfigurationListener> configurationListeners,
+ final long lastModifiedMillis) {
+ super(configuration, reconfigurable, configurationListeners);
+ this.watcher = watcher;
+ this.lastModifiedMillis = lastModifiedMillis;
+ }
+
+
+ public WrappedFileWatcher(FileWatcher watcher) {
+ super(null, null, null);
+ this.watcher = watcher;
+ }
+
+ public long getLastModified() {
+ return lastModifiedMillis;
+ }
+
+ @Override
+ public void fileModified(File file) {
+ watcher.fileModified(file);
+ }
+
+ @Override
+ public boolean isModified() {
+ long lastModified = getSource().getFile().lastModified();
+ if (lastModifiedMillis != lastModified) {
+ lastModifiedMillis = lastModified;
+ return true;
+ }
+ return false;
+ }
+
+ @Override
+ public List<ConfigurationListener> getListeners() {
+ if (super.getListeners() != null) {
+ return Collections.unmodifiableList(super.getListeners());
+ } else {
+ return null;
+ }
+ }
+
+ @Override
+ public void modified() {
+ if (getListeners() != null) {
+ super.modified();
+ }
+ fileModified(getSource().getFile());
+ lastModifiedMillis = getSource().getFile().lastModified();
+ }
+
+ @Override
+ public void watching(Source source) {
+ lastModifiedMillis = source.getFile().lastModified();
+ super.watching(source);
+ }
+
+ @Override
+ public Watcher newWatcher(final Reconfigurable reconfigurable, final List<ConfigurationListener> listeners,
+ long lastModifiedMillis) {
+ WrappedFileWatcher watcher = new WrappedFileWatcher(this.watcher, getConfiguration(), reconfigurable, listeners,
+ lastModifiedMillis);
+ if (getSource() != null) {
+ watcher.watching(getSource());
+ }
+ return watcher;
+ }
+}
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/util/WatchHttpTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/util/WatchHttpTest.java
new file mode 100644
index 0000000..f9b5abf
--- /dev/null
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/util/WatchHttpTest.java
@@ -0,0 +1,175 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache license, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the license for the specific language governing permissions and
+ * limitations under the license.
+ */
+package org.apache.logging.log4j.core.util;
+
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.List;
+import java.util.Queue;
+import java.util.TimeZone;
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.logging.log4j.core.config.Configuration;
+import org.apache.logging.log4j.core.config.ConfigurationListener;
+import org.apache.logging.log4j.core.config.ConfigurationScheduler;
+import org.apache.logging.log4j.core.config.DefaultConfiguration;
+import org.apache.logging.log4j.core.config.HttpWatcher;
+import org.apache.logging.log4j.core.config.Reconfigurable;
+import org.apache.logging.log4j.core.net.ssl.TestConstants;
+import org.apache.logging.log4j.core.util.datetime.FastDateFormat;
+import org.apache.logging.log4j.util.PropertiesUtil;
+import org.junit.After;
+import org.junit.Assume;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Rule;
+import org.junit.Test;
+
+import com.github.tomakehurst.wiremock.junit.WireMockRule;
+import com.github.tomakehurst.wiremock.stubbing.StubMapping;
+
+import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
+import static com.github.tomakehurst.wiremock.client.WireMock.get;
+import static com.github.tomakehurst.wiremock.client.WireMock.removeStub;
+import static com.github.tomakehurst.wiremock.client.WireMock.stubFor;
+import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo;
+import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+
+/**
+ * Test the WatchManager
+ */
+public class WatchHttpTest {
+
+ private static final String FORCE_RUN_KEY = WatchHttpTest.class.getSimpleName() + ".forceRun";
+ private final String file = "log4j-test1.xml";
+ private static FastDateFormat formatter;
+ private static final String XML = "application/xml";
+
+ private static final boolean IS_WINDOWS = PropertiesUtil.getProperties().isOsWindows();
+
+ @BeforeClass
+ public static void beforeClass() {
+ try {
+ formatter = FastDateFormat.getInstance("EEE, dd MMM yyyy HH:mm:ss", TimeZone.getTimeZone("UTC"));
+ } catch (Exception ex) {
+ System.err.println("Unable to create date format.");
+ ex.printStackTrace();
+ throw ex;
+ }
+ }
+
+ @Rule
+ public WireMockRule wireMockRule = new WireMockRule(wireMockConfig().dynamicPort().dynamicHttpsPort()
+ .keystorePath(TestConstants.KEYSTORE_FILE)
+ .keystorePassword(String.valueOf(TestConstants.KEYSTORE_PWD()))
+ .keystoreType(TestConstants.KEYSTORE_TYPE));
+
+ @Test
+ public void testWatchManager() throws Exception {
+ BlockingQueue<String> queue = new LinkedBlockingQueue<>();
+ List<ConfigurationListener> listeners = new ArrayList<>();
+ listeners.add(new TestConfigurationListener(queue, "log4j-test1.xml"));
+ TimeZone timeZone = TimeZone.getTimeZone("UTC");
+ Calendar now = Calendar.getInstance(timeZone);
+ Calendar previous = now;
+ previous.add(Calendar.MINUTE, -5);
+ Configuration configuration = new DefaultConfiguration();
+ Assume.assumeTrue(!IS_WINDOWS || Boolean.getBoolean(FORCE_RUN_KEY));
+ URL url = new URL("http://localhost:" + wireMockRule.port() + "/log4j-test1.xml");
+ StubMapping stubMapping = stubFor(get(urlPathEqualTo("/log4j-test1.xml"))
+ .willReturn(aResponse()
+ .withBodyFile(file)
+ .withStatus(200)
+ .withHeader("Last-Modified", formatter.format(previous) + " GMT")
+ .withHeader("Content-Type", XML)));
+ final ConfigurationScheduler scheduler = new ConfigurationScheduler();
+ scheduler.incrementScheduledItems();
+ final WatchManager watchManager = new WatchManager(scheduler);
+ watchManager.setIntervalSeconds(1);
+ scheduler.start();
+ watchManager.start();
+ try {
+ watchManager.watch(new Source(url.toURI(), previous.getTimeInMillis()), new HttpWatcher(configuration, null,
+ listeners, previous.getTimeInMillis()));
+ Thread.sleep(1500);
+ final String str = queue.poll(1, TimeUnit.SECONDS);
+ assertNotNull("File change not detected", str);
+ } finally {
+ removeStub(stubMapping);
+ watchManager.stop();
+ scheduler.stop();
+ }
+ }
+
+ @Test
+ public void testNotModified() throws Exception {
+ BlockingQueue<String> queue = new LinkedBlockingQueue<>();
+ List<ConfigurationListener> listeners = new ArrayList<>();
+ listeners.add(new TestConfigurationListener(queue, "log4j-test2.xml"));
+ TimeZone timeZone = TimeZone.getTimeZone("UTC");
+ Calendar now = Calendar.getInstance(timeZone);
+ Calendar previous = now;
+ previous.add(Calendar.MINUTE, -5);
+ Configuration configuration = new DefaultConfiguration();
+ Assume.assumeTrue(!IS_WINDOWS || Boolean.getBoolean(FORCE_RUN_KEY));
+ URL url = new URL("http://localhost:" + wireMockRule.port() + "/log4j-test2.xml");
+ StubMapping stubMapping = stubFor(get(urlPathEqualTo("/log4j-test2.xml"))
+ .willReturn(aResponse()
+ .withBodyFile(file)
+ .withStatus(304)
+ .withHeader("Last-Modified", formatter.format(now) + " GMT")
+ .withHeader("Content-Type", XML)));
+ final ConfigurationScheduler scheduler = new ConfigurationScheduler();
+ scheduler.incrementScheduledItems();
+ final WatchManager watchManager = new WatchManager(scheduler);
+ watchManager.setIntervalSeconds(1);
+ scheduler.start();
+ watchManager.start();
+ try {
+ watchManager.watch(new Source(url.toURI(), previous.getTimeInMillis()), new HttpWatcher(configuration, null,
+ listeners, previous.getTimeInMillis()));
+ Thread.sleep(1500);
+ final String str = queue.poll(1, TimeUnit.SECONDS);
+ assertNull("File changed.", str);
+ } finally {
+ removeStub(stubMapping);
+ watchManager.stop();
+ scheduler.stop();
+ }
+ }
+
+ private class TestConfigurationListener implements ConfigurationListener {
+ private final Queue<String> queue;
+ private final String name;
+
+ public TestConfigurationListener(final Queue<String> queue, String name) {
+ this.queue = queue;
+ this.name = name;
+ }
+
+ @Override
+ public void onChange(Reconfigurable reconfigurable) {
+ //System.out.println("Reconfiguration detected for " + name);
+ queue.add(name);
+ }
+ }
+}
diff --git a/log4j-core/src/test/resources/__files/log4j-test1.xml b/log4j-core/src/test/resources/__files/log4j-test1.xml
new file mode 100644
index 0000000..3598aec
--- /dev/null
+++ b/log4j-core/src/test/resources/__files/log4j-test1.xml
@@ -0,0 +1,58 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+-->
+<Configuration status="OFF" name="XMLConfigTest">
+ <Properties>
+ <Property name="filename">target/test-xml.log</Property>
+ </Properties>
+ <ThresholdFilter level="debug"/>
+
+ <Appenders>
+ <Console name="STDOUT">
+ <PatternLayout pattern="%m%n"/>
+ </Console>
+ <File name="File" fileName="${filename}" bufferedIO="false">
+ <PatternLayout>
+ <Pattern>%d %p %C{1.} [%t] %m%n</Pattern>
+ </PatternLayout>
+ </File>
+ <List name="List">
+ <Filters>
+ <ThresholdFilter level="error"/>
+ </Filters>
+ </List>
+ </Appenders>
+
+ <Loggers>
+ <Logger name="org.apache.logging.log4j.test1" level="debug" additivity="false">
+ <ThreadContextMapFilter>
+ <KeyValuePair key="test" value="123"/>
+ </ThreadContextMapFilter>
+ <AppenderRef ref="STDOUT"/>
+ </Logger>
+
+ <Logger name="org.apache.logging.log4j.test2" level="debug" additivity="false">
+ <AppenderRef ref="File"/>
+ </Logger>
+
+ <Root level="error">
+ <AppenderRef ref="STDOUT"/>
+ </Root>
+ </Loggers>
+
+</Configuration>
\ No newline at end of file
diff --git a/log4j-spring-cloud-config/log4j-spring-cloud-config-client/pom.xml b/log4j-spring-cloud-config/log4j-spring-cloud-config-client/pom.xml
new file mode 100644
index 0000000..8799078
--- /dev/null
+++ b/log4j-spring-cloud-config/log4j-spring-cloud-config-client/pom.xml
@@ -0,0 +1,196 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.logging.log4j</groupId>
+ <artifactId>log4j-spring-cloud-config</artifactId>
+ <version>2.11.2-SNAPSHOT</version>
+ <relativePath>../</relativePath>
+ </parent>
+ <artifactId>log4j-spring-cloud-config-client</artifactId>
+ <packaging>jar</packaging>
+ <name>Apache Log4j Spring Cloud Config Client Support</name>
+ <description></description>
+ <properties>
+ <log4jParentDir>${basedir}/..</log4jParentDir>
+ <docLabel>Log4j Spring Cloud Config Client Documentation</docLabel>
+ <projectDir>/log4j-spring-cloud-config-client</projectDir>
+ <module.name>org.apache.logging.log4j.spring.cloud.config.client</module.name>
+ </properties>
+ <dependencies>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework.cloud</groupId>
+ <artifactId>spring-cloud-config-client</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.hamcrest</groupId>
+ <artifactId>hamcrest-all</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>commons-logging</groupId>
+ <artifactId>commons-logging</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.logging.log4j</groupId>
+ <artifactId>log4j-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.logging.log4j</groupId>
+ <artifactId>log4j-core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.logging.log4j</groupId>
+ <artifactId>log4j-core</artifactId>
+ <type>test-jar</type>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+ <build>
+ <plugins>
+ <!-- Include the standard NOTICE and LICENSE -->
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-remote-resources-plugin</artifactId>
+ <executions>
+ <execution>
+ <goals>
+ <goal>process</goal>
+ </goals>
+ <configuration>
+ <skip>false</skip>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <configuration>
+ <instructions>
+ <Export-Package>org.apache.logging.log4j.spring.cloud.config.controller</Export-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ <reporting>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-changes-plugin</artifactId>
+ <version>${changes.plugin.version}</version>
+ <reportSets>
+ <reportSet>
+ <reports>
+ <report>changes-report</report>
+ </reports>
+ </reportSet>
+ </reportSets>
+ <configuration>
+ <issueLinkTemplate>%URL%/show_bug.cgi?id=%ISSUE%</issueLinkTemplate>
+ <useJql>true</useJql>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-checkstyle-plugin</artifactId>
+ <version>${checkstyle.plugin.version}</version>
+ <configuration>
+ <!--<propertiesLocation>${vfs.parent.dir}/checkstyle.properties</propertiesLocation> -->
+ <configLocation>${log4jParentDir}/checkstyle.xml</configLocation>
+ <suppressionsLocation>${log4jParentDir}/checkstyle-suppressions.xml</suppressionsLocation>
+ <enableRulesSummary>false</enableRulesSummary>
+ <propertyExpansion>basedir=${basedir}</propertyExpansion>
+ <propertyExpansion>licensedir=${log4jParentDir}/checkstyle-header.txt</propertyExpansion>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-javadoc-plugin</artifactId>
+ <version>${javadoc.plugin.version}</version>
+ <configuration>
+ <bottom><![CDATA[<p align="center">Copyright © {inceptionYear}-{currentYear} {organizationName}. All Rights Reserved.<br />
+ Apache Logging, Apache Log4j, Log4j, Apache, the Apache feather logo, the Apache Logging project logo,
+ and the Apache Log4j logo are trademarks of The Apache Software Foundation.</p>]]></bottom>
+ <!-- module link generation is completely broken in the javadoc plugin for a multi-module non-aggregating
+ project -->
+ <detectOfflineLinks>false</detectOfflineLinks>
+ <linksource>true</linksource>
+ </configuration>
+ <reportSets>
+ <reportSet>
+ <id>non-aggregate</id>
+ <reports>
+ <report>javadoc</report>
+ </reports>
+ </reportSet>
+ </reportSets>
+ </plugin>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>findbugs-maven-plugin</artifactId>
+ <version>${findbugs.plugin.version}</version>
+ <configuration>
+ <fork>true</fork>
+ <jvmArgs>-Duser.language=en</jvmArgs>
+ <threshold>Normal</threshold>
+ <effort>Default</effort>
+ <excludeFilterFile>${log4jParentDir}/findbugs-exclude-filter.xml</excludeFilterFile>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-jxr-plugin</artifactId>
+ <version>${jxr.plugin.version}</version>
+ <reportSets>
+ <reportSet>
+ <id>non-aggregate</id>
+ <reports>
+ <report>jxr</report>
+ </reports>
+ </reportSet>
+ <reportSet>
+ <id>aggregate</id>
+ <reports>
+ <report>aggregate</report>
+ </reports>
+ </reportSet>
+ </reportSets>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-pmd-plugin</artifactId>
+ <version>${pmd.plugin.version}</version>
+ <configuration>
+ <targetJdk>${maven.compiler.target}</targetJdk>
+ </configuration>
+ </plugin>
+ </plugins>
+ </reporting>
+</project>
diff --git a/log4j-spring-cloud-config/log4j-spring-cloud-config-client/src/main/java/org/apache/logging/log4j/spring/cloud/config/client/Log4j2CloudConfigLoggingSystem.java b/log4j-spring-cloud-config/log4j-spring-cloud-config-client/src/main/java/org/apache/logging/log4j/spring/cloud/config/client/Log4j2CloudConfigLoggingSystem.java
new file mode 100644
index 0000000..05b02f9
--- /dev/null
+++ b/log4j-spring-cloud-config/log4j-spring-cloud-config-client/src/main/java/org/apache/logging/log4j/spring/cloud/config/client/Log4j2CloudConfigLoggingSystem.java
@@ -0,0 +1,127 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache license, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the license for the specific language governing permissions and
+ * limitations under the license.
+ */
+package org.apache.logging.log4j.spring.cloud.config.client;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.net.URLConnection;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Properties;
+import javax.net.ssl.HttpsURLConnection;
+
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+import org.apache.logging.log4j.core.LoggerContext;
+import org.apache.logging.log4j.core.config.ConfigurationFactory;
+import org.apache.logging.log4j.core.config.ConfigurationSource;
+import org.apache.logging.log4j.core.net.ssl.LaxHostnameVerifier;
+import org.apache.logging.log4j.core.net.ssl.SslConfiguration;
+import org.apache.logging.log4j.core.net.ssl.SslConfigurationFactory;
+import org.apache.logging.log4j.core.util.FileUtils;
+import org.apache.logging.log4j.status.StatusLogger;
+import org.apache.logging.log4j.util.PropertiesUtil;
+import org.springframework.boot.logging.LogFile;
+import org.springframework.boot.logging.LoggingInitializationContext;
+import org.springframework.boot.logging.log4j2.Log4J2LoggingSystem;
+import org.springframework.core.io.ClassPathResource;
+import org.springframework.util.Assert;
+import org.springframework.util.ClassUtils;
+import org.springframework.util.ResourceUtils;
+
+/**
+ *
+ */
+public class Log4j2CloudConfigLoggingSystem extends Log4J2LoggingSystem {
+ private static final String FILE_PROTOCOL = "file";
+ private static final String HTTPS = "https";
+ private Logger LOGGER = StatusLogger.getLogger();
+
+ public Log4j2CloudConfigLoggingSystem(ClassLoader loader) {
+ super(loader);
+ }
+
+ @Override
+ protected String[] getStandardConfigLocations() {
+ String[] locations = super.getStandardConfigLocations();
+ PropertiesUtil props = new PropertiesUtil(new Properties());
+ String location = props.getStringProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY);
+ if (location != null) {
+ List<String> list = Arrays.asList(super.getStandardConfigLocations());
+ list.add(location);
+ locations = list.toArray(new String[list.size()]);
+ }
+ return locations;
+ }
+
+ @Override
+ protected void loadDefaults(LoggingInitializationContext initializationContext, LogFile logFile) {
+ if (logFile != null) {
+ this.loadConfiguration(this.getBootPackagedConfigFile("log4j2-file.xml"), logFile);
+ } else {
+ this.loadConfiguration(this.getBootPackagedConfigFile("log4j2.xml"), logFile);
+ }
+ }
+
+ private String getBootPackagedConfigFile(String fileName) {
+ String defaultPath = ClassUtils.getPackageName(Log4J2LoggingSystem.class);
+ defaultPath = defaultPath.replace('.', '/');
+ defaultPath = defaultPath + "/" + fileName;
+ defaultPath = "classpath:" + defaultPath;
+ return defaultPath;
+ }
+
+ @Override
+ protected void loadConfiguration(String location, LogFile logFile) {
+ Assert.notNull(location, "Location must not be null");
+ try {
+ LoggerContext ctx = getLoggerContext();
+ URL url = ResourceUtils.getURL(location);
+ ConfigurationSource source = getConfigurationSource(url);
+ ctx.start(ConfigurationFactory.getInstance().getConfiguration(ctx, source));
+ }
+ catch (Exception ex) {
+ throw new IllegalStateException(
+ "Could not initialize Log4J2 logging from " + location, ex);
+ }
+ }
+
+ private ConfigurationSource getConfigurationSource(URL url) throws IOException, URISyntaxException {
+ URLConnection urlConnection = url.openConnection();
+ if (url.getProtocol().equals(HTTPS)) {
+ SslConfiguration sslConfiguration = SslConfigurationFactory.getSslConfiguration();
+ if (sslConfiguration != null) {
+ ((HttpsURLConnection) urlConnection).setSSLSocketFactory(sslConfiguration.getSslSocketFactory());
+ if (!sslConfiguration.isVerifyHostName()) {
+ ((HttpsURLConnection) urlConnection).setHostnameVerifier(LaxHostnameVerifier.INSTANCE);
+ }
+ }
+ }
+ File file = FileUtils.fileFromUri(url.toURI());
+ if (file != null) {
+ return new ConfigurationSource(urlConnection.getInputStream(), FileUtils.fileFromUri(url.toURI()));
+ } else {
+ return new ConfigurationSource(urlConnection.getInputStream(), url, urlConnection.getLastModified());
+ }
+ }
+
+ private LoggerContext getLoggerContext() {
+ return (LoggerContext) LogManager.getContext(false);
+ }
+}
diff --git a/log4j-spring-cloud-config/log4j-spring-cloud-config-client/src/main/resources/log4j2.system.properties b/log4j-spring-cloud-config/log4j-spring-cloud-config-client/src/main/resources/log4j2.system.properties
new file mode 100644
index 0000000..918a074
--- /dev/null
+++ b/log4j-spring-cloud-config/log4j-spring-cloud-config-client/src/main/resources/log4j2.system.properties
@@ -0,0 +1 @@
+org.springframework.boot.logging.LoggingSystem=org.apache.logging.log4j.spring.cloud.config.client.Log4j2CloudConfigLoggingSystem
\ No newline at end of file
diff --git a/log4j-spring-cloud-config/log4j-spring-cloud-config-server/pom.xml b/log4j-spring-cloud-config/log4j-spring-cloud-config-server/pom.xml
new file mode 100644
index 0000000..6a31ce6
--- /dev/null
+++ b/log4j-spring-cloud-config/log4j-spring-cloud-config-server/pom.xml
@@ -0,0 +1,205 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.logging.log4j</groupId>
+ <artifactId>log4j-spring-cloud-config</artifactId>
+ <version>2.11.2-SNAPSHOT</version>
+ <relativePath>../</relativePath>
+ </parent>
+ <artifactId>log4j-spring-cloud-config-server</artifactId>
+ <packaging>jar</packaging>
+ <name>Apache Log4j Spring Cloud Config Server Support</name>
+ <description></description>
+ <properties>
+ <log4jParentDir>${basedir}/..</log4jParentDir>
+ <docLabel>Log4j Spring Cloud Config Server Documentation</docLabel>
+ <projectDir>/log4j-spring-cloud-config-server</projectDir>
+ <module.name>org.apache.logging.log4j.spring.cloud.config.controller</module.name>
+ <log4j.version>2.11.2-SNAPSHOT</log4j.version>
+ </properties>
+ <dependencies>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework.cloud</groupId>
+ <artifactId>spring-cloud-config-server</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-web</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-webmvc</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.hamcrest</groupId>
+ <artifactId>hamcrest-all</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>commons-logging</groupId>
+ <artifactId>commons-logging</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.logging.log4j</groupId>
+ <artifactId>log4j-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.logging.log4j</groupId>
+ <artifactId>log4j-core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.logging.log4j</groupId>
+ <artifactId>log4j-core</artifactId>
+ <type>test-jar</type>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+ <build>
+ <plugins>
+ <!-- Include the standard NOTICE and LICENSE -->
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-remote-resources-plugin</artifactId>
+ <executions>
+ <execution>
+ <goals>
+ <goal>process</goal>
+ </goals>
+ <configuration>
+ <skip>false</skip>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <configuration>
+ <instructions>
+ <Export-Package>org.apache.logging.log4j.spring.cloud.config.controller</Export-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ <reporting>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-changes-plugin</artifactId>
+ <version>${changes.plugin.version}</version>
+ <reportSets>
+ <reportSet>
+ <reports>
+ <report>changes-report</report>
+ </reports>
+ </reportSet>
+ </reportSets>
+ <configuration>
+ <issueLinkTemplate>%URL%/show_bug.cgi?id=%ISSUE%</issueLinkTemplate>
+ <useJql>true</useJql>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-checkstyle-plugin</artifactId>
+ <version>${checkstyle.plugin.version}</version>
+ <configuration>
+ <!--<propertiesLocation>${vfs.parent.dir}/checkstyle.properties</propertiesLocation> -->
+ <configLocation>${log4jParentDir}/checkstyle.xml</configLocation>
+ <suppressionsLocation>${log4jParentDir}/checkstyle-suppressions.xml</suppressionsLocation>
+ <enableRulesSummary>false</enableRulesSummary>
+ <propertyExpansion>basedir=${basedir}</propertyExpansion>
+ <propertyExpansion>licensedir=${log4jParentDir}/checkstyle-header.txt</propertyExpansion>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-javadoc-plugin</artifactId>
+ <version>${javadoc.plugin.version}</version>
+ <configuration>
+ <bottom><![CDATA[<p align="center">Copyright © {inceptionYear}-{currentYear} {organizationName}. All Rights Reserved.<br />
+ Apache Logging, Apache Log4j, Log4j, Apache, the Apache feather logo, the Apache Logging project logo,
+ and the Apache Log4j logo are trademarks of The Apache Software Foundation.</p>]]></bottom>
+ <!-- module link generation is completely broken in the javadoc plugin for a multi-module non-aggregating
+ project -->
+ <detectOfflineLinks>false</detectOfflineLinks>
+ <linksource>true</linksource>
+ </configuration>
+ <reportSets>
+ <reportSet>
+ <id>non-aggregate</id>
+ <reports>
+ <report>javadoc</report>
+ </reports>
+ </reportSet>
+ </reportSets>
+ </plugin>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>findbugs-maven-plugin</artifactId>
+ <version>${findbugs.plugin.version}</version>
+ <configuration>
+ <fork>true</fork>
+ <jvmArgs>-Duser.language=en</jvmArgs>
+ <threshold>Normal</threshold>
+ <effort>Default</effort>
+ <excludeFilterFile>${log4jParentDir}/findbugs-exclude-filter.xml</excludeFilterFile>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-jxr-plugin</artifactId>
+ <version>${jxr.plugin.version}</version>
+ <reportSets>
+ <reportSet>
+ <id>non-aggregate</id>
+ <reports>
+ <report>jxr</report>
+ </reports>
+ </reportSet>
+ <reportSet>
+ <id>aggregate</id>
+ <reports>
+ <report>aggregate</report>
+ </reports>
+ </reportSet>
+ </reportSets>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-pmd-plugin</artifactId>
+ <version>${pmd.plugin.version}</version>
+ <configuration>
+ <targetJdk>${maven.compiler.target}</targetJdk>
+ </configuration>
+ </plugin>
+ </plugins>
+ </reporting>
+</project>
diff --git a/log4j-spring-cloud-config/log4j-spring-cloud-config-server/src/main/java/org/apache/logging/log4j/spring/cloud/config/server/controller/Log4jResourceController.java b/log4j-spring-cloud-config/log4j-spring-cloud-config-server/src/main/java/org/apache/logging/log4j/spring/cloud/config/server/controller/Log4jResourceController.java
new file mode 100644
index 0000000..e6bdd66
--- /dev/null
+++ b/log4j-spring-cloud-config/log4j-spring-cloud-config-server/src/main/java/org/apache/logging/log4j/spring/cloud/config/server/controller/Log4jResourceController.java
@@ -0,0 +1,200 @@
+/*
+ * Copyright 2015-2016 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.logging.log4j.spring.cloud.config.server.controller;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.charset.Charset;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.cloud.config.environment.Environment;
+import org.springframework.cloud.config.server.environment.EnvironmentRepository;
+import org.springframework.cloud.config.server.resource.NoSuchResourceException;
+import org.springframework.cloud.config.server.resource.ResourceRepository;
+import org.springframework.core.io.Resource;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.MediaType;
+import org.springframework.util.StreamUtils;
+import org.springframework.web.bind.annotation.ExceptionHandler;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.ResponseStatus;
+import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.context.request.ServletWebRequest;
+import org.springframework.web.util.UrlPathHelper;
+
+import static org.springframework.cloud.config.server.support.EnvironmentPropertySource.prepareEnvironment;
+import static org.springframework.cloud.config.server.support.EnvironmentPropertySource.resolvePlaceholders;
+
+/**
+ * Modified version of Spring Cloud Config's ResourceController to support If-Modified-Since.
+ * Should be dropeed when Spring implements this.
+ *
+ * An HTTP endpoint for serving up templated plain text resources from an underlying
+ * repository. Can be used to supply config files for consumption by a wide variety of
+ * applications and services. A {@link ResourceRepository} is used to locate a
+ * {@link Resource}, specific to an application, and the contents are transformed to text.
+ * Then an {@link EnvironmentRepository} is used to supply key-value pairs which are used
+ * to replace placeholders in the resource text.
+ *
+ * @author Dave Syer
+ * @author Daniel Lavoie
+ *
+ */
+@RestController
+@RequestMapping(method = RequestMethod.GET, path = "${spring.cloud.config.server.prefix:}/resource")
+public class Log4jResourceController {
+
+ @Autowired
+ private ResourceRepository resourceRepository;
+
+ @Autowired
+ private EnvironmentRepository environmentRepository;
+
+ private UrlPathHelper helper = new UrlPathHelper();
+
+ public Log4jResourceController(ResourceRepository resourceRepository,
+ EnvironmentRepository environmentRepository) {
+ this.resourceRepository = resourceRepository;
+ this.environmentRepository = environmentRepository;
+ this.helper.setAlwaysUseFullPath(true);
+ }
+
+ @RequestMapping("/{name}/{profile}/{label}/**")
+ public String retrieve(@PathVariable String name, @PathVariable String profile,
+ @PathVariable String label, ServletWebRequest request,
+ @RequestParam(defaultValue = "true") boolean resolvePlaceholders)
+ throws IOException {
+ String path = getFilePath(request, name, profile, label);
+ return retrieve(request, name, profile, label, path, resolvePlaceholders);
+ }
+
+ @RequestMapping(value = "/{name}/{profile}/**", params = "useDefaultLabel")
+ public String retrieve(@PathVariable String name, @PathVariable String profile,
+ ServletWebRequest request, @RequestParam(defaultValue = "true") boolean resolvePlaceholders)
+ throws IOException {
+ String path = getFilePath(request, name, profile, null);
+ return retrieve(request, name, profile, null, path, resolvePlaceholders);
+ }
+
+ private String getFilePath(ServletWebRequest request, String name, String profile,
+ String label) {
+ String stem;
+ if(label != null ) {
+ stem = String.format("/%s/%s/%s/", name, profile, label);
+ }else {
+ stem = String.format("/%s/%s/", name, profile);
+ }
+ String path = this.helper.getPathWithinApplication(request.getRequest());
+ path = path.substring(path.indexOf(stem) + stem.length());
+ return path;
+ }
+
+ private synchronized String retrieve(ServletWebRequest request, String name, String profile, String label,
+ String path, boolean resolvePlaceholders) throws IOException {
+ name = resolveName(name);
+ label = resolveLabel(label);
+ Resource resource = this.resourceRepository.findOne(name, profile, label, path);
+ if (checkNotModified(request, resource)) {
+ // Content was not modified. Just return.
+ return null;
+ }
+ // ensure InputStream will be closed to prevent file locks on Windows
+ try (InputStream is = resource.getInputStream()) {
+ String text = StreamUtils.copyToString(is, Charset.forName("UTF-8"));
+ if (resolvePlaceholders) {
+ Environment environment = this.environmentRepository.findOne(name, profile, label);
+ text = resolvePlaceholders(prepareEnvironment(environment), text);
+ }
+ return text;
+ }
+ }
+
+ /*
+ * Used only for unit tests.
+ */
+ String retrieve(String name, String profile, String label, String path,
+ boolean resolvePlaceholders) throws IOException {
+ return retrieve(null, name, profile, label, path, resolvePlaceholders);
+ }
+
+ @RequestMapping(value = "/{name}/{profile}/{label}/**", produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
+ public synchronized byte[] binary(@PathVariable String name,
+ @PathVariable String profile, @PathVariable String label,
+ ServletWebRequest request) throws IOException {
+ String path = getFilePath(request, name, profile, label);
+ return binary(request, name, profile, label, path);
+ }
+
+ /*
+ * Used only for unit tests.
+ */
+ byte[] binary(String name, String profile, String label, String path) throws IOException {
+ return binary(null, name, profile, label, path);
+ }
+
+ private synchronized byte[] binary(ServletWebRequest request, String name, String profile, String label,
+ String path) throws IOException {
+ name = resolveName(name);
+ label = resolveLabel(label);
+ Resource resource = this.resourceRepository.findOne(name, profile, label, path);
+ if (checkNotModified(request, resource)) {
+ // Content was not modified. Just return.
+ return null;
+ }
+ // TODO: is this line needed for side effects?
+ prepareEnvironment(this.environmentRepository.findOne(name, profile, label));
+ try (InputStream is = resource.getInputStream()) {
+ return StreamUtils.copyToByteArray(is);
+ }
+ }
+
+ private boolean checkNotModified(ServletWebRequest request, Resource resource) {
+ try {
+ return request != null && request.checkNotModified(resource.lastModified());
+ } catch (Exception ex) {
+ // Ignore the exception since caching is optional.
+ }
+ return false;
+ }
+
+ private String resolveName(String name) {
+ if (name != null && name.contains("(_)")) {
+ // "(_)" is uncommon in a git repo name, but "/" cannot be matched
+ // by Spring MVC
+ name = name.replace("(_)", "/");
+ }
+ return name;
+ }
+
+ private String resolveLabel(String label) {
+ if (label != null && label.contains("(_)")) {
+ // "(_)" is uncommon in a git branch name, but "/" cannot be matched
+ // by Spring MVC
+ label = label.replace("(_)", "/");
+ }
+ return label;
+ }
+
+ @ExceptionHandler(NoSuchResourceException.class)
+ @ResponseStatus(HttpStatus.NOT_FOUND)
+ public void notFound(NoSuchResourceException e) {
+ }
+
+}
diff --git a/log4j-spring-cloud-config/log4j-spring-cloud-config-server/src/main/resources/META-INF/spring.factories b/log4j-spring-cloud-config/log4j-spring-cloud-config-server/src/main/resources/META-INF/spring.factories
new file mode 100644
index 0000000..dadd13c
--- /dev/null
+++ b/log4j-spring-cloud-config/log4j-spring-cloud-config-server/src/main/resources/META-INF/spring.factories
@@ -0,0 +1 @@
+org.springframework.boot.autoconfigure.EnableAutoConfiguration=org.apache.logging.log4j.spring.cloud.config.server.controller.Log4jResourceController
\ No newline at end of file
diff --git a/log4j-spring-cloud-config/pom.xml b/log4j-spring-cloud-config/pom.xml
new file mode 100644
index 0000000..a736e86
--- /dev/null
+++ b/log4j-spring-cloud-config/pom.xml
@@ -0,0 +1,95 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.logging.log4j</groupId>
+ <artifactId>log4j</artifactId>
+ <version>2.11.2-SNAPSHOT</version>
+ <relativePath>../</relativePath>
+ </parent>
+ <groupId>org.apache.logging.log4j</groupId>
+ <artifactId>log4j-spring-cloud-config</artifactId>
+ <packaging>pom</packaging>
+ <name>Apache Log4j Spring Cloud Config Support</name>
+ <url>http://maven.apache.org</url>
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ <revapi.skip>true</revapi.skip>
+ <spring-cloud-config.version>2.0.3.BUILD-SNAPSHOT</spring-cloud-config.version>
+ <spring-boot.version>2.1.1.RELEASE</spring-boot.version>
+ <spring.version>5.0.5.RELEASE</spring.version>
+ </properties>
+ <dependencyManagement>
+ <dependencies>
+ <dependency>
+ <groupId>org.springframework.cloud</groupId>
+ <artifactId>spring-cloud-config-dependencies</artifactId>
+ <version>${spring-cloud-config.version}</version>
+ <type>pom</type>
+ <scope>import</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot</artifactId>
+ <version>${spring-boot.version}</version>
+ <type>pom</type>
+ <scope>import</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-web</artifactId>
+ <version>${spring.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-webmvc</artifactId>
+ <version>${spring.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.12</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+ </dependencyManagement>
+ <modules>
+ <module>log4j-spring-cloud-config-server</module>
+ <module>log4j-spring-cloud-config-client</module>
+ </modules>
+ <build>
+ <plugins>
+ <!-- Include the standard NOTICE and LICENSE -->
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-remote-resources-plugin</artifactId>
+ <executions>
+ <execution>
+ <goals>
+ <goal>process</goal>
+ </goals>
+ <configuration>
+ <skip>false</skip>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+</project>
diff --git a/pom.xml b/pom.xml
index df33a12..5333bb2 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1375,6 +1375,7 @@
<module>log4j-liquibase</module>
<module>log4j-appserver</module>
<module>log4j-osgi</module>
+ <module>log4j-spring-cloud-config</module>
</modules>
<profiles>
<profile>