logging-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rpo...@apache.org
Subject svn commit: r1481254 - in /logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/jmx: LoggerContextAdmin.java LoggerContextAdminMBean.java
Date Sat, 11 May 2013 03:27:14 GMT
Author: rpopma
Date: Sat May 11 03:27:14 2013
New Revision: 1481254

URL: http://svn.apache.org/r1481254
Log:
Use UTF8 by default when reading config text, added method to allow clients to specify other
encoding

Modified:
    logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/jmx/LoggerContextAdmin.java
    logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/jmx/LoggerContextAdminMBean.java

Modified: logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/jmx/LoggerContextAdmin.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/jmx/LoggerContextAdmin.java?rev=1481254&r1=1481253&r2=1481254&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/jmx/LoggerContextAdmin.java
(original)
+++ logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/jmx/LoggerContextAdmin.java
Sat May 11 03:27:14 2013
@@ -28,6 +28,7 @@ import java.io.Reader;
 import java.io.StringWriter;
 import java.net.URI;
 import java.net.URISyntaxException;
+import java.nio.charset.Charset;
 import java.util.Map;
 import java.util.concurrent.Executor;
 import java.util.concurrent.atomic.AtomicLong;
@@ -42,6 +43,7 @@ import org.apache.logging.log4j.core.con
 import org.apache.logging.log4j.core.config.ConfigurationFactory;
 import org.apache.logging.log4j.core.config.ConfigurationFactory.ConfigurationSource;
 import org.apache.logging.log4j.core.helpers.Assert;
+import org.apache.logging.log4j.core.helpers.Charsets;
 import org.apache.logging.log4j.status.StatusLogger;
 
 /**
@@ -144,11 +146,17 @@ public class LoggerContextAdmin extends 
 
     @Override
     public String getConfigText() throws IOException {
+        return getConfigText(Charsets.UTF_8.name());
+    }
+
+    @Override
+    public String getConfigText(String charsetName) throws IOException {
         if (customConfigText != null) {
             return customConfigText;
         }
         try {
-            return readContents(new URI(getConfigLocationURI()));
+            Charset charset = Charset.forName(charsetName);
+            return readContents(new URI(getConfigLocationURI()), charset);
         } catch (Exception ex) {
             StringWriter sw = new StringWriter(BUFFER_SIZE);
             ex.printStackTrace(new PrintWriter(sw));
@@ -179,11 +187,11 @@ public class LoggerContextAdmin extends 
         }
     }
 
-    private String readContents(URI uri) throws IOException {
+    private String readContents(URI uri, Charset charset) throws IOException {
         InputStream in = null;
         try {
             in = uri.toURL().openStream();
-            Reader reader = new InputStreamReader(in);
+            Reader reader = new InputStreamReader(in, charset);
             StringBuilder result = new StringBuilder(TEXT_BUFFER);
             char[] buff = new char[PAGE];
             int count = -1;

Modified: logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/jmx/LoggerContextAdminMBean.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/jmx/LoggerContextAdminMBean.java?rev=1481254&r1=1481253&r2=1481254&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/jmx/LoggerContextAdminMBean.java
(original)
+++ logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/jmx/LoggerContextAdminMBean.java
Sat May 11 03:27:14 2013
@@ -71,7 +71,8 @@ public interface LoggerContextAdminMBean
     /**
      * Returns the configuration text, which may be the contents of the
      * configuration file or the text that was last set with a call to
-     * {@code setConfigText}.
+     * {@code setConfigText}. If reading a file, this method assumes the file's
+     * character encoding is UTF-8.
      * 
      * @return the configuration text
      * @throws IOException if a problem occurred reading the contents of the
@@ -80,6 +81,19 @@ public interface LoggerContextAdminMBean
     String getConfigText() throws IOException;
 
     /**
+     * Returns the configuration text, which may be the contents of the
+     * configuration file or the text that was last set with a call to
+     * {@code setConfigText}.
+     * 
+     * @param charsetName the encoding to use to convert the file's bytes into
+     *            the resulting string.
+     * @return the configuration text
+     * @throws IOException if a problem occurred reading the contents of the
+     *             config file.
+     */
+    String getConfigText(String charsetName) throws IOException;
+
+    /**
      * Sets the configuration text. This does not replace the contents of the
      * configuration file, but <em>does</em> cause the instrumented
      * {@code LoggerContext} to be reconfigured with the specified text.



Mime
View raw message