logging-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rpo...@apache.org
Subject svn commit: r1562419 - in /logging/log4j/log4j2/trunk/log4j-core/src: main/java/org/apache/logging/log4j/core/jmx/Server.java test/java/org/apache/logging/log4j/core/jmx/ServerTest.java
Date Wed, 29 Jan 2014 11:40:03 GMT
Author: rpopma
Date: Wed Jan 29 11:40:03 2014
New Revision: 1562419

URL: http://svn.apache.org/r1562419
Log:
LOG4J2-492 escape contextName when unregistering LoggerContext, quote escaped newlines, drop
\r characters

Modified:
    logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/jmx/Server.java
    logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/jmx/ServerTest.java

Modified: logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/jmx/Server.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/jmx/Server.java?rev=1562419&r1=1562418&r2=1562419&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/jmx/Server.java
(original)
+++ logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/jmx/Server.java
Wed Jan 29 11:40:03 2014
@@ -88,12 +88,12 @@ public final class Server {
                 needsQuotes = true;
                 break;
             case '\r':
-                // replace by \\r, no need to quote
-                sb.append("\\r");
+                // drop \r characters: \\r gives "invalid escape sequence"
                 continue;
             case '\n':
-                // replace by \\n, no need to quote
+                // replace \n characters with \\n sequence
                 sb.append("\\n");
+                needsQuotes = true;
                 continue;
             }
             sb.append(c);
@@ -260,13 +260,14 @@ public final class Server {
      */
     public static void unregisterContext(String contextName, MBeanServer mbs) {
         final String pattern = LoggerContextAdminMBean.PATTERN;
-        final String search = String.format(pattern, contextName, "*");
+        final String safeContextName = escape(contextName);
+        final String search = String.format(pattern, safeContextName, "*");
         unregisterAllMatching(search, mbs); // unregister context mbean
-        unregisterLoggerConfigs(contextName, mbs);
-        unregisterAppenders(contextName, mbs);
-        unregisterAsyncAppenders(contextName, mbs);
-        unregisterAsyncLoggerRingBufferAdmins(contextName, mbs);
-        unregisterAsyncLoggerConfigRingBufferAdmins(contextName, mbs);
+        unregisterLoggerConfigs(safeContextName, mbs);
+        unregisterAppenders(safeContextName, mbs);
+        unregisterAsyncAppenders(safeContextName, mbs);
+        unregisterAsyncLoggerRingBufferAdmins(safeContextName, mbs);
+        unregisterAsyncLoggerConfigRingBufferAdmins(safeContextName, mbs);
     }
 
     private static void registerStatusLogger(final MBeanServer mbs, final Executor executor)

Modified: logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/jmx/ServerTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/jmx/ServerTest.java?rev=1562419&r1=1562418&r2=1562419&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/jmx/ServerTest.java
(original)
+++ logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/jmx/ServerTest.java
Wed Jan 29 11:40:03 2014
@@ -104,7 +104,7 @@ public class ServerTest {
     public void testEscapeEscapesLineFeed() throws Exception {
         final String ctx = "a\rc";
         final String ctxName = Server.escape(ctx);
-        assertEquals("a\\rc", ctxName);
+        assertEquals("ac", ctxName);
         new ObjectName(String.format(LoggerContextAdminMBean.PATTERN, ctxName)); 
         // no MalformedObjectNameException = success
     }
@@ -113,7 +113,7 @@ public class ServerTest {
     public void testEscapeEscapesCarriageReturn() throws Exception {
         final String ctx = "a\nc";
         final String ctxName = Server.escape(ctx);
-        assertEquals("a\\nc", ctxName);
+        assertEquals("\"a\\nc\"", ctxName);
         new ObjectName(String.format(LoggerContextAdminMBean.PATTERN, ctxName)); 
         // no MalformedObjectNameException = success
     }



Mime
View raw message