You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by rp...@apache.org on 2014/06/19 18:18:57 UTC
svn commit: r1603937 - in /logging/log4j/log4j2/trunk:
log4j-1.2-api/src/test/java/org/apache/log4j/
log4j-core/src/main/java/org/apache/logging/log4j/core/
log4j-core/src/main/java/org/apache/logging/log4j/core/config/
log4j-core/src/main/java/org/apa...
Author: rpopma
Date: Thu Jun 19 16:18:56 2014
New Revision: 1603937
URL: http://svn.apache.org/r1603937
Log:
LOG4J2-539: Fixed issue with "Reconfigure using XML below" function in JMX Client GUI.
ConfigurationSource is now a top-level class and can be obtained with Configuration.getConfigurationSource().
LoggerContext.getConfiguration().getConfigurationSource() provides a reliable public method for obtaining a logger context's configuration location and content.
Added:
logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/config/ConfigurationSource.java (with props)
Modified:
logging/log4j/log4j2/trunk/log4j-1.2-api/src/test/java/org/apache/log4j/BasicConfigurationFactory.java
logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/LoggerContext.java
logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/config/AbstractConfiguration.java
logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/config/Configuration.java
logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/config/ConfigurationFactory.java
logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/config/Configurator.java
logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/config/DefaultConfiguration.java
logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/config/NullConfiguration.java
logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/config/json/JsonConfiguration.java
logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/config/json/JsonConfigurationFactory.java
logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/config/xml/XmlConfiguration.java
logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/config/xml/XmlConfigurationFactory.java
logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/config/yaml/YamlConfiguration.java
logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/config/yaml/YamlConfigurationFactory.java
logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/Log4jContextFactory.java
logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/jmx/LoggerContextAdmin.java
logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/net/server/AbstractSocketServer.java
logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/Log4jInitPerformance.java
logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/BasicConfigurationFactory.java
logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/config/TestConfigurator.java
logging/log4j/log4j2/trunk/src/changes/changes.xml
Modified: logging/log4j/log4j2/trunk/log4j-1.2-api/src/test/java/org/apache/log4j/BasicConfigurationFactory.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-1.2-api/src/test/java/org/apache/log4j/BasicConfigurationFactory.java?rev=1603937&r1=1603936&r2=1603937&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-1.2-api/src/test/java/org/apache/log4j/BasicConfigurationFactory.java (original)
+++ logging/log4j/log4j2/trunk/log4j-1.2-api/src/test/java/org/apache/log4j/BasicConfigurationFactory.java Thu Jun 19 16:18:56 2014
@@ -22,6 +22,7 @@ import org.apache.logging.log4j.Level;
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.LoggerConfig;
/**
@@ -31,7 +32,7 @@ public class BasicConfigurationFactory e
@Override
public String[] getSupportedTypes() {
- return new String[] {"*"};
+ return new String[] { "*" };
}
@Override
@@ -49,10 +50,13 @@ public class BasicConfigurationFactory e
private static final String DEFAULT_LEVEL = "org.apache.logging.log4j.level";
public BasicConfiguration() {
+ super(ConfigurationSource.NULL_SOURCE);
+
final LoggerConfig root = getRootLogger();
setName("BasicConfiguration");
final String levelName = System.getProperty(DEFAULT_LEVEL);
- final Level level = (levelName != null && Level.getLevel(levelName) != null) ? Level.getLevel(levelName) : Level.DEBUG;
+ final Level level = (levelName != null && Level.getLevel(levelName) != null) ? Level.getLevel(levelName)
+ : Level.DEBUG;
root.setLevel(level);
}
Modified: logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/LoggerContext.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/LoggerContext.java?rev=1603937&r1=1603936&r2=1603937&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/LoggerContext.java (original)
+++ logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/LoggerContext.java Thu Jun 19 16:18:56 2014
@@ -35,6 +35,7 @@ import org.apache.logging.log4j.MarkerMa
import org.apache.logging.log4j.core.config.Configuration;
import org.apache.logging.log4j.core.config.ConfigurationFactory;
import org.apache.logging.log4j.core.config.ConfigurationListener;
+import org.apache.logging.log4j.core.config.ConfigurationSource;
import org.apache.logging.log4j.core.config.DefaultConfiguration;
import org.apache.logging.log4j.core.config.NullConfiguration;
import org.apache.logging.log4j.core.config.Reconfigurable;
@@ -386,10 +387,21 @@ public class LoggerContext extends Abstr
propertyChangeListeners.remove(listener);
}
+ /**
+ * Returns the initial configuration location or {@code null}. The returned value may not be the location of the
+ * current configuration. Use
+ * {@link #getConfiguration()}.{@link Configuration#getConfigurationSource() getConfigurationSource()}.{@link
+ * ConfigurationSource#getLocation() getLocation()} to get the actual source of the current configuration.
+ * @return the initial configuration location or {@code null}
+ */
public synchronized URI getConfigLocation() {
return configLocation;
}
+ /**
+ * Sets the configLocation to the specified value and reconfigures this context.
+ * @param configLocation the location of the new configuration
+ */
public synchronized void setConfigLocation(final URI configLocation) {
this.configLocation = configLocation;
reconfigure();
Modified: logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/config/AbstractConfiguration.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/config/AbstractConfiguration.java?rev=1603937&r1=1603936&r2=1603937&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/config/AbstractConfiguration.java (original)
+++ logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/config/AbstractConfiguration.java Thu Jun 19 16:18:56 2014
@@ -52,6 +52,7 @@ import org.apache.logging.log4j.core.loo
import org.apache.logging.log4j.core.lookup.StrSubstitutor;
import org.apache.logging.log4j.core.net.Advertiser;
import org.apache.logging.log4j.core.selector.ContextSelector;
+import org.apache.logging.log4j.core.util.Assert;
import org.apache.logging.log4j.core.util.Constants;
import org.apache.logging.log4j.core.util.Loader;
import org.apache.logging.log4j.core.util.NameUtil;
@@ -84,42 +85,38 @@ public abstract class AbstractConfigurat
* The Advertiser which exposes appender configurations to external systems.
*/
private Advertiser advertiser = new DefaultAdvertiser();
-
private Node advertiserNode = null;
-
private Object advertisement;
/**
*
*/
protected boolean isShutdownHookEnabled = true;
-
private String name;
-
private ConcurrentMap<String, Appender> appenders = new ConcurrentHashMap<String, Appender>();
-
private ConcurrentMap<String, LoggerConfig> loggers = new ConcurrentHashMap<String, LoggerConfig>();
-
private final ConcurrentMap<String, String> properties = new ConcurrentHashMap<String, String>();
-
private final StrLookup tempLookup = new Interpolator(properties);
-
private final StrSubstitutor subst = new StrSubstitutor(tempLookup);
-
private LoggerConfig root = new LoggerConfig();
-
private final ConcurrentMap<String, Object> componentMap = new ConcurrentHashMap<String, Object>();
-
protected PluginManager pluginManager;
+ private final ConfigurationSource configurationSource;
/**
* Constructor.
*/
- protected AbstractConfiguration() {
+ protected AbstractConfiguration(final ConfigurationSource configurationSource) {
+ this.configurationSource = Assert.requireNonNull(configurationSource, "configurationSource is null");
componentMap.put(Configuration.CONTEXT_PROPERTIES, properties);
pluginManager = new PluginManager("Core");
rootNode = new Node();
}
+
+ @Override
+ public ConfigurationSource getConfigurationSource() {
+ return configurationSource;
+ }
@Override
public Map<String, String> getProperties() {
@@ -279,7 +276,7 @@ public abstract class AbstractConfigurat
}
}
- protected void createAdvertiser(String advertiserString, ConfigurationFactory.ConfigurationSource configSource,
+ protected void createAdvertiser(String advertiserString, ConfigurationSource configSource,
byte[] buffer, String contentType) {
if (advertiserString != null) {
Node node = new Node(null, advertiserString, null);
Modified: logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/config/Configuration.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/config/Configuration.java?rev=1603937&r1=1603936&r2=1603937&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/config/Configuration.java (original)
+++ logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/config/Configuration.java Thu Jun 19 16:18:56 2014
@@ -98,4 +98,10 @@ public interface Configuration extends F
Advertiser getAdvertiser();
boolean isShutdownHookEnabled();
+
+ /**
+ * Returns the source of this configuration.
+ * @return the source of this configuration
+ */
+ ConfigurationSource getConfigurationSource();
}
Modified: logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/config/ConfigurationFactory.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/config/ConfigurationFactory.java?rev=1603937&r1=1603936&r2=1603937&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/config/ConfigurationFactory.java (original)
+++ logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/config/ConfigurationFactory.java Thu Jun 19 16:18:56 2014
@@ -262,7 +262,7 @@ public abstract class ConfigurationFacto
}
}
try {
- return new ConfigurationSource(configLocation.toURL().openStream(), configLocation.getPath());
+ return new ConfigurationSource(configLocation.toURL().openStream(), configLocation.toURL());
} catch (final MalformedURLException ex) {
LOGGER.error("Invalid URL {}", configLocation.toString(), ex);
} catch (final Exception ex) {
@@ -326,7 +326,7 @@ public abstract class ConfigurationFacto
LOGGER.catching(Level.DEBUG, ex);
}
}
- return new ConfigurationSource(is, resource);
+ return new ConfigurationSource(is, url);
}
/**
@@ -489,72 +489,4 @@ public abstract class ConfigurationFacto
return null;
}
}
-
- /**
- * Represents the source for the logging configuration.
- */
- public static class ConfigurationSource {
-
- private File file;
-
- private String location;
-
- private InputStream stream;
-
- public ConfigurationSource() {
- }
-
- public ConfigurationSource(final InputStream stream) {
- this.stream = stream;
- this.file = null;
- this.location = null;
- }
-
- public ConfigurationSource(final InputStream stream, final File file) {
- this.stream = stream;
- this.file = file;
- this.location = file.getAbsolutePath();
- }
-
- public ConfigurationSource(final InputStream stream, final String location) {
- this.stream = stream;
- this.location = location;
- this.file = null;
- }
-
- public File getFile() {
- return file;
- }
-
- public void setFile(final File file) {
- this.file = file;
- }
-
- public String getLocation() {
- return location;
- }
-
- public void setLocation(final String location) {
- this.location = location;
- }
-
- public InputStream getInputStream() {
- return stream;
- }
-
- public void setInputStream(final InputStream stream) {
- this.stream = stream;
- }
-
- @Override
- public String toString() {
- if (file != null) {
- return file.getAbsolutePath();
- }
- if (location != null) {
- return location;
- }
- return "stream (unknown location)";
- }
- }
}
Added: logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/config/ConfigurationSource.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/config/ConfigurationSource.java?rev=1603937&view=auto
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/config/ConfigurationSource.java (added)
+++ logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/config/ConfigurationSource.java Thu Jun 19 16:18:56 2014
@@ -0,0 +1,177 @@
+/*
+ * 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.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+
+import org.apache.logging.log4j.core.util.Assert;
+
+/**
+ * Represents the source for the logging configuration.
+ */
+public class ConfigurationSource {
+ public static final ConfigurationSource NULL_SOURCE = new ConfigurationSource(new byte[0]);
+
+ private final File file;
+ private final URL url;
+ private final String location;
+ private final InputStream stream;
+ private final byte[] data;
+
+ /**
+ * Returns the contents of the specified {@code InputStream} as a byte array.
+ *
+ * @param inputStream the stream to read
+ * @return the contents of the specified stream
+ * @throws IOException if a problem occurred reading from the stream
+ */
+ private static byte[] toByteArray(final InputStream inputStream) throws IOException {
+ final int buffSize = Math.max(4096, inputStream.available());
+ final ByteArrayOutputStream contents = new ByteArrayOutputStream(buffSize);
+ final byte[] buff = new byte[buffSize];
+
+ int length = inputStream.read(buff);
+ while (length > 0) {
+ contents.write(buff, 0, length);
+ length = inputStream.read(buff);
+ }
+ return contents.toByteArray();
+ }
+
+ /**
+ * Constructs a new {@code ConfigurationSource} with the specified input stream. Since the stream is the only source
+ * of data, this constructor makes a copy of the stream contents.
+ *
+ * @param stream the input stream
+ * @throws IOException if an exception occurred reading from the specified stream
+ */
+ public ConfigurationSource(final InputStream stream) throws IOException {
+ this(toByteArray(stream));
+ }
+
+ private ConfigurationSource(final byte[] data) {
+ this.data = Assert.requireNonNull(data, "data is null");
+ this.stream = new ByteArrayInputStream(data);
+ this.file = null;
+ this.url = null;
+ this.location = null;
+ }
+
+ /**
+ * Constructs a new {@code ConfigurationSource} with the specified input stream that originated from the specified
+ * file.
+ *
+ * @param stream the input stream
+ * @param file the file where the input stream originated
+ */
+ public ConfigurationSource(final InputStream stream, final File file) {
+ this.stream = Assert.requireNonNull(stream, "stream is null");
+ this.file = Assert.requireNonNull(file, "file is null");
+ this.location = file.getAbsolutePath();
+ this.url = null;
+ this.data = null;
+ }
+
+ /**
+ * 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
+ */
+ public ConfigurationSource(final InputStream stream, final URL url) {
+ this.stream = Assert.requireNonNull(stream, "stream is null");
+ this.url = Assert.requireNonNull(url, "URL is null");
+ this.location = url.toString();
+ this.file = null;
+ this.data = 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 URL getURL() {
+ return url;
+ }
+
+ /**
+ * 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;
+ }
+
+ /**
+ * Returns the input stream that this configuration source was constructed with.
+ *
+ * @return the input stream that this configuration source was constructed with.
+ */
+ public InputStream getInputStream() {
+ return stream;
+ }
+
+ /**
+ * Returns a new {@code ConfigurationSource} whose input stream is reset to the beginning.
+ *
+ * @return a new {@code ConfigurationSource}
+ * @throws IOException if a problem occurred while opening the new input stream
+ */
+ public ConfigurationSource resetInputStream() throws IOException {
+ if (file != null) {
+ return new ConfigurationSource(new FileInputStream(file), file);
+ } else if (url != null) {
+ return new ConfigurationSource(url.openStream(), url);
+ } else {
+ return new ConfigurationSource(data);
+ }
+ }
+
+ @Override
+ public String toString() {
+ if (location != null) {
+ return location;
+ }
+ if (this == NULL_SOURCE) {
+ return "NULL_SOURCE";
+ }
+ int length = data == null ? -1 : data.length;
+ return "stream (" + length + " bytes, unknown location)";
+ }
+}
\ No newline at end of file
Propchange: logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/config/ConfigurationSource.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/config/Configurator.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/config/Configurator.java?rev=1603937&r1=1603936&r2=1603937&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/config/Configurator.java (original)
+++ logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/config/Configurator.java Thu Jun 19 16:18:56 2014
@@ -123,7 +123,7 @@ public final class Configurator {
* @return The LoggerContext.
*/
public static LoggerContext initialize(final ClassLoader loader,
- final ConfigurationFactory.ConfigurationSource source) {
+ final ConfigurationSource source) {
return initialize(loader, source, null);
}
@@ -136,7 +136,7 @@ public final class Configurator {
*/
public static LoggerContext initialize(final ClassLoader loader,
- final ConfigurationFactory.ConfigurationSource source,
+ final ConfigurationSource source,
final Object externalContext)
{
Modified: logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/config/DefaultConfiguration.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/config/DefaultConfiguration.java?rev=1603937&r1=1603936&r2=1603937&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/config/DefaultConfiguration.java (original)
+++ logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/config/DefaultConfiguration.java Thu Jun 19 16:18:56 2014
@@ -50,7 +50,8 @@ public class DefaultConfiguration extend
* Constructor to create the default configuration.
*/
public DefaultConfiguration() {
-
+ super(ConfigurationSource.NULL_SOURCE);
+
setName(DEFAULT_NAME);
final Layout<? extends Serializable> layout = PatternLayout.newBuilder()
.withPattern(DEFAULT_PATTERN)
Modified: logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/config/NullConfiguration.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/config/NullConfiguration.java?rev=1603937&r1=1603936&r2=1603937&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/config/NullConfiguration.java (original)
+++ logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/config/NullConfiguration.java Thu Jun 19 16:18:56 2014
@@ -26,6 +26,7 @@ public class NullConfiguration extends A
public static final String NULL_NAME = "Null";
public NullConfiguration() {
+ super(ConfigurationSource.NULL_SOURCE);
setName(NULL_NAME);
final LoggerConfig root = getRootLogger();
Modified: logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/config/json/JsonConfiguration.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/config/json/JsonConfiguration.java?rev=1603937&r1=1603936&r2=1603937&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/config/json/JsonConfiguration.java (original)
+++ logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/config/json/JsonConfiguration.java Thu Jun 19 16:18:56 2014
@@ -18,8 +18,7 @@ package org.apache.logging.log4j.core.co
import java.io.ByteArrayInputStream;
import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
+import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Iterator;
@@ -28,7 +27,7 @@ import java.util.Map;
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.FileConfigurationMonitor;
import org.apache.logging.log4j.core.config.Node;
import org.apache.logging.log4j.core.config.Reconfigurable;
@@ -47,16 +46,13 @@ import com.fasterxml.jackson.databind.Ob
*/
public class JsonConfiguration extends AbstractConfiguration implements Reconfigurable {
- private static final String[] VERBOSE_CLASSES = new String[]{ResolverUtil.class.getName()};
-
+ private static final String[] VERBOSE_CLASSES = new String[] { ResolverUtil.class.getName() };
private final List<Status> status = new ArrayList<Status>();
-
private JsonNode root;
- private final File configFile;
-
- public JsonConfiguration(final ConfigurationFactory.ConfigurationSource configSource) {
- this.configFile = configSource.getFile();
+ public JsonConfiguration(final ConfigurationSource configSource) {
+ super(configSource);
+ final File configFile = configSource.getFile();
byte[] buffer;
try {
final InputStream configStream = configSource.getInputStream();
@@ -73,8 +69,7 @@ public class JsonConfiguration extends A
}
}
processAttributes(rootNode, root);
- final StatusConfiguration statusConfig = new StatusConfiguration()
- .withVerboseClasses(VERBOSE_CLASSES)
+ final StatusConfiguration statusConfig = new StatusConfiguration().withVerboseClasses(VERBOSE_CLASSES)
.withStatus(getDefaultStatus());
for (final Map.Entry<String, String> entry : rootNode.getAttributes().entrySet()) {
final String key = entry.getKey();
@@ -140,14 +135,14 @@ public class JsonConfiguration extends A
@Override
public Configuration reconfigure() {
- if (configFile != null) {
- try {
- final ConfigurationFactory.ConfigurationSource source =
- new ConfigurationFactory.ConfigurationSource(new FileInputStream(configFile), configFile);
- return new JsonConfiguration(source);
- } catch (final FileNotFoundException ex) {
- LOGGER.error("Cannot locate file {}", configFile, ex);
- }
+ try {
+ final ConfigurationSource source = getConfigurationSource().resetInputStream();
+ if (source == null) {
+ return null;
+ }
+ return new JsonConfiguration(source);
+ } catch (final IOException ex) {
+ LOGGER.error("Cannot locate file {}", getConfigurationSource(), ex);
}
return null;
}
@@ -212,8 +207,8 @@ public class JsonConfiguration extends A
t = type.getElementName() + ':' + type.getPluginClass();
}
- final String p = node.getParent() == null ? "null" : node.getParent().getName() == null ?
- "root" : node.getParent().getName();
+ final String p = node.getParent() == null ? "null" : node.getParent().getName() == null ? "root" : node
+ .getParent().getName();
LOGGER.debug("Returning {} with parent {} of type {}", node.getName(), p, t);
return node;
}
@@ -245,11 +240,10 @@ public class JsonConfiguration extends A
}
}
}
-
+
@Override
public String toString() {
- final String path = configFile != null ? configFile.getAbsolutePath() : "unknown";
- return getClass().getSimpleName() + "[location=" + path + "]";
+ return getClass().getSimpleName() + "[location=" + getConfigurationSource() + "]";
}
/**
Modified: logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/config/json/JsonConfigurationFactory.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/config/json/JsonConfigurationFactory.java?rev=1603937&r1=1603936&r2=1603937&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/config/json/JsonConfigurationFactory.java (original)
+++ logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/config/json/JsonConfigurationFactory.java Thu Jun 19 16:18:56 2014
@@ -18,6 +18,7 @@ package org.apache.logging.log4j.core.co
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.Order;
import org.apache.logging.log4j.core.config.plugins.Plugin;
import org.apache.logging.log4j.core.util.Loader;
Modified: logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/config/xml/XmlConfiguration.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/config/xml/XmlConfiguration.java?rev=1603937&r1=1603936&r2=1603937&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/config/xml/XmlConfiguration.java (original)
+++ logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/config/xml/XmlConfiguration.java Thu Jun 19 16:18:56 2014
@@ -18,8 +18,6 @@ package org.apache.logging.log4j.core.co
import java.io.ByteArrayInputStream;
import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
@@ -38,7 +36,7 @@ import javax.xml.validation.Validator;
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.FileConfigurationMonitor;
import org.apache.logging.log4j.core.config.Node;
import org.apache.logging.log4j.core.config.Reconfigurable;
@@ -63,23 +61,15 @@ import org.xml.sax.SAXException;
public class XmlConfiguration extends AbstractConfiguration implements Reconfigurable {
private static final String XINCLUDE_FIXUP_LANGUAGE = "http://apache.org/xml/features/xinclude/fixup-language";
-
private static final String XINCLUDE_FIXUP_BASE_URIS = "http://apache.org/xml/features/xinclude/fixup-base-uris";
-
- private static final String[] VERBOSE_CLASSES = new String[] {ResolverUtil.class.getName()};
-
+ private static final String[] VERBOSE_CLASSES = new String[] { ResolverUtil.class.getName() };
private static final String LOG4J_XSD = "Log4j-config.xsd";
private final List<Status> status = new ArrayList<Status>();
-
private Element rootElement;
-
private boolean strict;
-
private String schema;
- private final File configFile;
-
/**
* Creates a new DocumentBuilder suitable for parsing a configuration file.
*
@@ -128,8 +118,9 @@ public class XmlConfiguration extends Ab
}
}
- public XmlConfiguration(final ConfigurationFactory.ConfigurationSource configSource) {
- this.configFile = configSource.getFile();
+ public XmlConfiguration(final ConfigurationSource configSource) {
+ super(configSource);
+ final File configFile = configSource.getFile();
byte[] buffer = null;
try {
@@ -143,8 +134,7 @@ public class XmlConfiguration extends Ab
final Document document = newDocumentBuilder().parse(source);
rootElement = document.getDocumentElement();
final Map<String, String> attrs = processAttributes(rootNode, rootElement);
- final StatusConfiguration statusConfig = new StatusConfiguration()
- .withVerboseClasses(VERBOSE_CLASSES)
+ final StatusConfiguration statusConfig = new StatusConfiguration().withVerboseClasses(VERBOSE_CLASSES)
.withStatus(getDefaultStatus());
for (final Map.Entry<String, String> entry : attrs.entrySet()) {
final String key = entry.getKey();
@@ -237,15 +227,15 @@ public class XmlConfiguration extends Ab
@Override
public Configuration reconfigure() {
- if (configFile != null) {
- try {
- final ConfigurationFactory.ConfigurationSource source =
- new ConfigurationFactory.ConfigurationSource(new FileInputStream(configFile), configFile);
- final XmlConfiguration config = new XmlConfiguration(source);
- return (config.rootElement == null) ? null : config;
- } catch (final FileNotFoundException ex) {
- LOGGER.error("Cannot locate file " + configFile, ex);
+ try {
+ final ConfigurationSource source = getConfigurationSource().resetInputStream();
+ if (source == null) {
+ return null;
}
+ final XmlConfiguration config = new XmlConfiguration(source);
+ return (config.rootElement == null) ? null : config;
+ } catch (final IOException ex) {
+ LOGGER.error("Cannot locate file " + getConfigurationSource(), ex);
}
return null;
}
@@ -322,8 +312,7 @@ public class XmlConfiguration extends Ab
@Override
public String toString() {
- final String path = configFile != null ? configFile.getAbsolutePath() : "unknown";
- return getClass().getSimpleName() + "[location=" + path + "]";
+ return getClass().getSimpleName() + "[location=" + getConfigurationSource() + "]";
}
/**
Modified: logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/config/xml/XmlConfigurationFactory.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/config/xml/XmlConfigurationFactory.java?rev=1603937&r1=1603936&r2=1603937&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/config/xml/XmlConfigurationFactory.java (original)
+++ logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/config/xml/XmlConfigurationFactory.java Thu Jun 19 16:18:56 2014
@@ -18,6 +18,7 @@ package org.apache.logging.log4j.core.co
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.Order;
import org.apache.logging.log4j.core.config.plugins.Plugin;
Modified: logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/config/yaml/YamlConfiguration.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/config/yaml/YamlConfiguration.java?rev=1603937&r1=1603936&r2=1603937&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/config/yaml/YamlConfiguration.java (original)
+++ logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/config/yaml/YamlConfiguration.java Thu Jun 19 16:18:56 2014
@@ -16,7 +16,7 @@
*/
package org.apache.logging.log4j.core.config.yaml;
-import org.apache.logging.log4j.core.config.ConfigurationFactory;
+import org.apache.logging.log4j.core.config.ConfigurationSource;
import org.apache.logging.log4j.core.config.json.JsonConfiguration;
import com.fasterxml.jackson.core.JsonParser;
@@ -25,7 +25,7 @@ import com.fasterxml.jackson.dataformat.
public class YamlConfiguration extends JsonConfiguration {
- public YamlConfiguration(ConfigurationFactory.ConfigurationSource configSource) {
+ public YamlConfiguration(ConfigurationSource configSource) {
super(configSource);
}
Modified: logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/config/yaml/YamlConfigurationFactory.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/config/yaml/YamlConfigurationFactory.java?rev=1603937&r1=1603936&r2=1603937&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/config/yaml/YamlConfigurationFactory.java (original)
+++ logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/config/yaml/YamlConfigurationFactory.java Thu Jun 19 16:18:56 2014
@@ -18,6 +18,7 @@ package org.apache.logging.log4j.core.co
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.Order;
import org.apache.logging.log4j.core.config.plugins.Plugin;
import org.apache.logging.log4j.core.util.Loader;
Modified: logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/Log4jContextFactory.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/Log4jContextFactory.java?rev=1603937&r1=1603936&r2=1603937&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/Log4jContextFactory.java (original)
+++ logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/Log4jContextFactory.java Thu Jun 19 16:18:56 2014
@@ -22,6 +22,7 @@ import org.apache.logging.log4j.core.Lif
import org.apache.logging.log4j.core.LoggerContext;
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.selector.ClassLoaderContextSelector;
import org.apache.logging.log4j.core.selector.ContextSelector;
import org.apache.logging.log4j.core.util.Constants;
@@ -87,7 +88,7 @@ public class Log4jContextFactory impleme
* @return The LoggerContext.
*/
public LoggerContext getContext(final String fqcn, final ClassLoader loader, final Object externalContext,
- final boolean currentContext, final ConfigurationFactory.ConfigurationSource source) {
+ final boolean currentContext, final ConfigurationSource source) {
final LoggerContext ctx = selector.getContext(fqcn, loader, currentContext, null);
if (externalContext != null && ctx.getExternalContext() == null) {
ctx.setExternalContext(externalContext);
Modified: logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/jmx/LoggerContextAdmin.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/jmx/LoggerContextAdmin.java?rev=1603937&r1=1603936&r2=1603937&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/jmx/LoggerContextAdmin.java (original)
+++ logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/jmx/LoggerContextAdmin.java Thu Jun 19 16:18:56 2014
@@ -20,14 +20,15 @@ import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.io.ByteArrayInputStream;
import java.io.File;
+import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.Reader;
import java.io.StringWriter;
-import java.net.URI;
import java.net.URISyntaxException;
+import java.net.URL;
import java.nio.charset.Charset;
import java.util.Map;
import java.util.concurrent.Executor;
@@ -41,19 +42,18 @@ import javax.management.ObjectName;
import org.apache.logging.log4j.core.LoggerContext;
import org.apache.logging.log4j.core.config.Configuration;
import org.apache.logging.log4j.core.config.ConfigurationFactory;
-import org.apache.logging.log4j.core.config.ConfigurationFactory.ConfigurationSource;
+import org.apache.logging.log4j.core.config.ConfigurationSource;
import org.apache.logging.log4j.core.util.Assert;
import org.apache.logging.log4j.core.util.Charsets;
import org.apache.logging.log4j.core.util.Closer;
-import org.apache.logging.log4j.core.util.FileUtils;
import org.apache.logging.log4j.status.StatusLogger;
import org.apache.logging.log4j.util.Strings;
/**
* Implementation of the {@code LoggerContextAdminMBean} interface.
*/
-public class LoggerContextAdmin extends NotificationBroadcasterSupport
- implements LoggerContextAdminMBean, PropertyChangeListener {
+public class LoggerContextAdmin extends NotificationBroadcasterSupport implements LoggerContextAdminMBean,
+ PropertyChangeListener {
private static final int PAGE = 4 * 1024;
private static final int TEXT_BUFFER = 64 * 1024;
private static final int BUFFER_SIZE = 2048;
@@ -62,11 +62,10 @@ public class LoggerContextAdmin extends
private final AtomicLong sequenceNo = new AtomicLong();
private final ObjectName objectName;
private final LoggerContext loggerContext;
- private String customConfigText;
/**
- * Constructs a new {@code LoggerContextAdmin} with the {@code Executor} to
- * be used for sending {@code Notification}s asynchronously to listeners.
+ * Constructs a new {@code LoggerContextAdmin} with the {@code Executor} to be used for sending {@code Notification}
+ * s asynchronously to listeners.
*
* @param executor used to send notifications asynchronously
* @param loggerContext the instrumented object
@@ -85,8 +84,7 @@ public class LoggerContextAdmin extends
}
private static MBeanNotificationInfo createNotificationInfo() {
- final String[] notifTypes = new String[] {//
- NOTIF_TYPE_RECONFIGURED };
+ final String[] notifTypes = new String[] { NOTIF_TYPE_RECONFIGURED };
final String name = Notification.class.getName();
final String description = "Configuration reconfigured";
return new MBeanNotificationInfo(notifTypes, name, description);
@@ -118,18 +116,24 @@ public class LoggerContextAdmin extends
}
@Override
- public void setConfigLocationUri(final String configLocation)
- throws URISyntaxException, IOException {
+ public void setConfigLocationUri(final String configLocation) throws URISyntaxException, IOException {
+ if (configLocation == null || configLocation.isEmpty()) {
+ throw new IllegalArgumentException("Missing configuration location");
+ }
LOGGER.debug("---------");
- LOGGER.debug("Remote request to reconfigure using location "
- + configLocation);
- final URI uri = FileUtils.getCorrectedFilePathUri(configLocation);
-
- // validate the location first: invalid location will result in
- // default configuration being configured, try to avoid that...
- uri.toURL().openStream().close();
-
- loggerContext.setConfigLocation(uri);
+ LOGGER.debug("Remote request to reconfigure using location " + configLocation);
+ final File configFile = new File(configLocation);
+ ConfigurationSource configSource = null;
+ if (configFile.exists()) {
+ LOGGER.debug("Opening config file {}", configFile.getAbsolutePath());
+ configSource = new ConfigurationSource(new FileInputStream(configFile), configFile);
+ } else {
+ final URL configURL = new URL(configLocation);
+ LOGGER.debug("Opening config URL {}", configURL);
+ configSource = new ConfigurationSource(configURL.openStream(), configURL);
+ }
+ final Configuration config = ConfigurationFactory.getInstance().getConfiguration(configSource);
+ loggerContext.start(config);
LOGGER.debug("Completed remote request to reconfigure.");
}
@@ -138,12 +142,7 @@ public class LoggerContextAdmin extends
if (!LoggerContext.PROPERTY_CONFIG.equals(evt.getPropertyName())) {
return;
}
- // erase custom text if new configuration was read from a location
- if (loggerContext.getConfiguration().getName() != null) {
- customConfigText = null;
- }
- final Notification notif = new Notification(NOTIF_TYPE_RECONFIGURED,
- getObjectName(), nextSeqNo(), now(), null);
+ final Notification notif = new Notification(NOTIF_TYPE_RECONFIGURED, getObjectName(), nextSeqNo(), now(), null);
sendNotification(notif);
}
@@ -154,12 +153,11 @@ public class LoggerContextAdmin extends
@Override
public String getConfigText(final String charsetName) throws IOException {
- if (customConfigText != null) {
- return customConfigText;
- }
try {
+ final ConfigurationSource source = loggerContext.getConfiguration().getConfigurationSource();
+ final ConfigurationSource copy = source.resetInputStream();
final Charset charset = Charset.forName(charsetName);
- return readContents(FileUtils.getCorrectedFilePathUri(getConfigLocationUri()), charset);
+ return readContents(copy.getInputStream(), charset);
} catch (final Exception ex) {
final StringWriter sw = new StringWriter(BUFFER_SIZE);
ex.printStackTrace(new PrintWriter(sw));
@@ -167,41 +165,16 @@ public class LoggerContextAdmin extends
}
}
- @Override
- public void setConfigText(final String configText, final String charsetName) {
- final String old = customConfigText;
- customConfigText = Assert.requireNonNull(configText, "configText");
- LOGGER.debug("---------");
- LOGGER.debug("Remote request to reconfigure from config text.");
-
- try {
- final InputStream in = new ByteArrayInputStream(
- configText.getBytes(charsetName));
- final ConfigurationSource source = new ConfigurationSource(in);
- final Configuration updated = ConfigurationFactory.getInstance()
- .getConfiguration(source);
- loggerContext.start(updated);
- LOGGER.debug("Completed remote request to reconfigure from config text.");
- } catch (final Exception ex) {
- customConfigText = old;
- final String msg = "Could not reconfigure from config text";
- LOGGER.error(msg, ex);
- throw new IllegalArgumentException(msg, ex);
- }
- }
-
/**
- *
- * @param uri
+ * Returns the contents of the specified input stream as a String.
+ * @param in stream to read from
* @param charset MUST not be null
- * @return
- * @throws IOException
+ * @return stream contents
+ * @throws IOException if a problem occurred reading from the stream.
*/
- private String readContents(final URI uri, final Charset charset) throws IOException {
- InputStream in = null;
+ private String readContents(final InputStream in, final Charset charset) throws IOException {
Reader reader = null;
try {
- in = uri.toURL().openStream();
reader = new InputStreamReader(in, charset);
final StringBuilder result = new StringBuilder(TEXT_BUFFER);
final char[] buff = new char[PAGE];
@@ -217,6 +190,24 @@ public class LoggerContextAdmin extends
}
@Override
+ public void setConfigText(final String configText, final String charsetName) {
+ LOGGER.debug("---------");
+ LOGGER.debug("Remote request to reconfigure from config text.");
+
+ try {
+ final InputStream in = new ByteArrayInputStream(configText.getBytes(charsetName));
+ final ConfigurationSource source = new ConfigurationSource(in);
+ final Configuration updated = ConfigurationFactory.getInstance().getConfiguration(source);
+ loggerContext.start(updated);
+ LOGGER.debug("Completed remote request to reconfigure from config text.");
+ } catch (final Exception ex) {
+ final String msg = "Could not reconfigure from config text";
+ LOGGER.error(msg, ex);
+ throw new IllegalArgumentException(msg, ex);
+ }
+ }
+
+ @Override
public String getConfigName() {
return getConfig().getName();
}
Modified: logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/net/server/AbstractSocketServer.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/net/server/AbstractSocketServer.java?rev=1603937&r1=1603936&r2=1603937&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/net/server/AbstractSocketServer.java (original)
+++ logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/net/server/AbstractSocketServer.java Thu Jun 19 16:18:56 2014
@@ -29,6 +29,7 @@ import org.apache.logging.log4j.LogManag
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.core.LogEventListener;
import org.apache.logging.log4j.core.config.Configuration;
+import org.apache.logging.log4j.core.config.ConfigurationSource;
import org.apache.logging.log4j.core.config.xml.XmlConfiguration;
import org.apache.logging.log4j.core.config.xml.XmlConfigurationFactory;
import org.apache.logging.log4j.core.util.Assert;
@@ -68,7 +69,7 @@ public abstract class AbstractSocketServ
if (source == null) {
try {
final URL url = new URL(path);
- source = new ConfigurationSource(url.openStream(), path);
+ source = new ConfigurationSource(url.openStream(), url);
} catch (final MalformedURLException mue) {
// Ignore this error
} catch (final IOException ioe) {
Modified: logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/Log4jInitPerformance.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/Log4jInitPerformance.java?rev=1603937&r1=1603936&r2=1603937&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/Log4jInitPerformance.java (original)
+++ logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/Log4jInitPerformance.java Thu Jun 19 16:18:56 2014
@@ -20,7 +20,7 @@ import java.io.ByteArrayInputStream;
import java.io.InputStream;
import org.apache.logging.log4j.categories.PerformanceTests;
-import org.apache.logging.log4j.core.config.ConfigurationFactory;
+import org.apache.logging.log4j.core.config.ConfigurationSource;
import org.apache.logging.log4j.core.config.Configurator;
import org.junit.Test;
import org.junit.experimental.categories.Category;
@@ -46,8 +46,8 @@ public class Log4jInitPerformance {
"</Loggers>" +
"</Configuration>";
final InputStream is = new ByteArrayInputStream(log4jConfigString.getBytes());
- final ConfigurationFactory.ConfigurationSource source =
- new ConfigurationFactory.ConfigurationSource(is);
+ final ConfigurationSource source =
+ new ConfigurationSource(is);
final long begin = System.currentTimeMillis();
Configurator.initialize(null, source);
final long tookForInit = System.currentTimeMillis() - begin;
Modified: logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/BasicConfigurationFactory.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/BasicConfigurationFactory.java?rev=1603937&r1=1603936&r2=1603937&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/BasicConfigurationFactory.java (original)
+++ logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/BasicConfigurationFactory.java Thu Jun 19 16:18:56 2014
@@ -22,6 +22,7 @@ import org.apache.logging.log4j.Level;
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.LoggerConfig;
/**
@@ -49,6 +50,7 @@ public class BasicConfigurationFactory e
private static final String DEFAULT_LEVEL = "org.apache.logging.log4j.level";
public BasicConfiguration() {
+ super(ConfigurationSource.NULL_SOURCE);
final LoggerConfig root = getRootLogger();
final String l = System.getProperty(DEFAULT_LEVEL);
Modified: logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/config/TestConfigurator.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/config/TestConfigurator.java?rev=1603937&r1=1603936&r2=1603937&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/config/TestConfigurator.java (original)
+++ logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/config/TestConfigurator.java Thu Jun 19 16:18:56 2014
@@ -95,9 +95,9 @@ public class TestConfigurator {
@Test
public void testFromStream() throws Exception {
- final InputStream is = new FileInputStream("target/test-classes/log4j2-config.xml");
- final ConfigurationFactory.ConfigurationSource source =
- new ConfigurationFactory.ConfigurationSource(is, "target/test-classes/log4j2-config.xml");
+ final File file = new File("target/test-classes/log4j2-config.xml");
+ final InputStream is = new FileInputStream(file);
+ final ConfigurationSource source = new ConfigurationSource(is, file);
ctx = Configurator.initialize(null, source);
LogManager.getLogger("org.apache.test.TestConfigurator");
Configuration config = ctx.getConfiguration();
@@ -115,8 +115,8 @@ public class TestConfigurator {
@Test
public void testFromStreamNoId() throws Exception {
final InputStream is = new FileInputStream("target/test-classes/log4j2-config.xml");
- final ConfigurationFactory.ConfigurationSource source =
- new ConfigurationFactory.ConfigurationSource(is);
+ final ConfigurationSource source =
+ new ConfigurationSource(is);
ctx = Configurator.initialize(null, source);
LogManager.getLogger("org.apache.test.TestConfigurator");
Configuration config = ctx.getConfiguration();
Modified: logging/log4j/log4j2/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/src/changes/changes.xml?rev=1603937&r1=1603936&r2=1603937&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/src/changes/changes.xml (original)
+++ logging/log4j/log4j2/trunk/src/changes/changes.xml Thu Jun 19 16:18:56 2014
@@ -22,6 +22,12 @@
</properties>
<body>
<release version="2.0-rc2" date="2014-MM-DD" description="Bug fixes and enhancements">
+ <action issue="LOG4J2-539" dev="rpopma" type="fix" due-to="Colin Froggatt">
+ Fixed issue with "Reconfigure using XML below" function in JMX Client GUI.
+ ConfigurationSource is now a top-level class and can be obtained with Configuration.getConfigurationSource().
+ LoggerContext.getConfiguration().getConfigurationSource()
+ provides a reliable public method for obtaining a logger context's configuration location and content.
+ </action>
<action issue="LOG4J2-619" dev="rgoers" type="fix" due-to="Scott Harrington">
Invalid XML configuration files do not prevent the config file from being checked again.
</action>