You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by ma...@apache.org on 2014/05/25 06:12:05 UTC

svn commit: r1597378 - in /logging/log4j/log4j2/trunk/log4j-core/src: main/java/org/apache/logging/log4j/core/layout/ test/java/org/apache/logging/log4j/core/layout/ test/java/org/apache/logging/log4j/core/net/server/

Author: mattsicker
Date: Sun May 25 04:12:04 2014
New Revision: 1597378

URL: http://svn.apache.org/r1597378
Log:
Update JsonLayout to use typed parameters in factory methods.

  - Also fixed typos in javadoc (XML -> JSON).

Modified:
    logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/JsonLayout.java
    logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/JsonLayoutTest.java
    logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/net/server/AbstractSocketServerTest.java

Modified: logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/JsonLayout.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/JsonLayout.java?rev=1597378&r1=1597377&r2=1597378&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/JsonLayout.java (original)
+++ logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/JsonLayout.java Sun May 25 04:12:04 2014
@@ -22,6 +22,7 @@ import java.util.Map;
 
 import org.apache.logging.log4j.core.config.plugins.Plugin;
 import org.apache.logging.log4j.core.config.plugins.PluginAttribute;
+import org.apache.logging.log4j.core.config.plugins.PluginDefault;
 import org.apache.logging.log4j.core.config.plugins.PluginFactory;
 import org.apache.logging.log4j.core.util.Charsets;
 
@@ -842,30 +843,34 @@ public final class JsonLayout extends Ab
     }
 
     /**
-     * Creates an XML Layout.
+     * Creates a JSON Layout.
      * 
      * @param locationInfo If "true", includes the location information in the generated JSON.
      * @param properties If "true", includes the thread context in the generated JSON.
-     * @param completeStr If "true", includes the JSON header and footer, defaults to "false".
-     * @param compactStr If "true", does not use end-of-lines and indentation, defaults to "false".
-     * @param charsetName The character set to use, if {@code null}, uses "UTF-8".
-     * @return An XML Layout.
+     * @param complete If "true", includes the JSON header and footer, defaults to "false".
+     * @param compact If "true", does not use end-of-lines and indentation, defaults to "false".
+     * @param charset The character set to use, if {@code null}, uses "UTF-8".
+     * @return A JSON Layout.
      */
     @PluginFactory
     public static AbstractJacksonLayout createLayout(
             // @formatter:off
-            @PluginAttribute("locationInfo") final String locationInfo,
-            @PluginAttribute("properties") final String properties,
-            @PluginAttribute("complete") final String completeStr, 
-            @PluginAttribute("compact") final String compactStr,
-            @PluginAttribute("charset") final String charsetName
+            @PluginAttribute("locationInfo") @PluginDefault("false") final boolean locationInfo,
+            @PluginAttribute("properties") @PluginDefault("false") final boolean properties,
+            @PluginAttribute("complete") @PluginDefault("false") final boolean complete,
+            @PluginAttribute("compact") @PluginDefault("false") final boolean compact,
+            @PluginAttribute("charset") @PluginDefault("UTF-8") final Charset charset
             // @formatter:on
     ) {
-        final Charset charset = Charsets.getSupportedCharset(charsetName, Charsets.UTF_8);
-        final boolean info = Boolean.parseBoolean(locationInfo);
-        final boolean props = Boolean.parseBoolean(properties);
-        final boolean complete = Boolean.parseBoolean(completeStr);
-        final boolean compact = Boolean.parseBoolean(compactStr);
-        return new JsonLayout(info, props, complete, compact, charset);
+        return new JsonLayout(locationInfo, properties, complete, compact, charset);
+    }
+
+    /**
+     * Creates a JSON Layout using the default settings.
+     *
+     * @return A JSON Layout.
+     */
+    public static AbstractJacksonLayout createDefaultLayout() {
+        return new JsonLayout(false, false, false, false, Charsets.UTF_8);
     }
 }

Modified: logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/JsonLayoutTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/JsonLayoutTest.java?rev=1597378&r1=1597377&r2=1597378&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/JsonLayoutTest.java (original)
+++ logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/JsonLayoutTest.java Sun May 25 04:12:04 2014
@@ -103,8 +103,8 @@ public class JsonLayoutTest {
     private void testAllFeatures(final boolean includeSource, final boolean compact, final boolean includeContext)
             throws Exception {
         final Log4jLogEvent expected = LogEventFixtures.createLogEvent();
-        final AbstractJacksonLayout layout = JsonLayout.createLayout(Boolean.toString(includeSource),
-                Boolean.toString(includeContext), "false", Boolean.toString(compact), "UTF-8");
+        final AbstractJacksonLayout layout = JsonLayout.createLayout(includeSource,
+                includeContext, false, compact, Charsets.UTF_8);
         final String str = layout.toSerializable(expected);
         // System.out.println(str);
         final String propSep = this.toPropertySeparator(compact);
@@ -160,13 +160,13 @@ public class JsonLayoutTest {
 
     @Test
     public void testContentType() {
-        final AbstractJacksonLayout layout = JsonLayout.createLayout(null, null, null, null, null);
+        final AbstractJacksonLayout layout = JsonLayout.createDefaultLayout();
         assertEquals("application/json; charset=UTF-8", layout.getContentType());
     }
 
     @Test
     public void testDefaultCharset() {
-        final AbstractJacksonLayout layout = JsonLayout.createLayout(null, null, null, null, null);
+        final AbstractJacksonLayout layout = JsonLayout.createDefaultLayout();
         assertEquals(Charsets.UTF_8, layout.getCharset());
     }
 
@@ -177,7 +177,7 @@ public class JsonLayoutTest {
             this.rootLogger.removeAppender(appender);
         }
         // set up appender
-        final AbstractJacksonLayout layout = JsonLayout.createLayout("true", "true", "true", "false", null);
+        final AbstractJacksonLayout layout = JsonLayout.createLayout(true, true, true, false, null);
         final ListAppender appender = new ListAppender("List", null, layout, true, false);
         appender.start();
 
@@ -212,7 +212,7 @@ public class JsonLayoutTest {
             this.rootLogger.removeAppender(appender);
         }
         // set up appender
-        final AbstractJacksonLayout layout = JsonLayout.createLayout("true", "true", "true", "false", null);
+        final AbstractJacksonLayout layout = JsonLayout.createLayout(true, true, true, false, null);
         final ListAppender appender = new ListAppender("List", null, layout, true, false);
         appender.start();
 
@@ -251,7 +251,7 @@ public class JsonLayoutTest {
 
     @Test
     public void testLayoutLoggerName() throws Exception {
-        final AbstractJacksonLayout layout = JsonLayout.createLayout("false", null, "false", "true", "UTF-8");
+        final AbstractJacksonLayout layout = JsonLayout.createLayout(false, false, false, true, Charsets.UTF_8);
         final Log4jLogEvent expected = Log4jLogEvent.createEvent("a.B", null, "f.q.c.n", Level.DEBUG, 
                 new SimpleMessage("M"), null, null, null, null, "threadName", null, 1);
         final String str = layout.toSerializable(expected);

Modified: logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/net/server/AbstractSocketServerTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/net/server/AbstractSocketServerTest.java?rev=1597378&r1=1597377&r2=1597378&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/net/server/AbstractSocketServerTest.java (original)
+++ logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/net/server/AbstractSocketServerTest.java Sun May 25 04:12:04 2014
@@ -89,7 +89,7 @@ public abstract class AbstractSocketServ
     }
 
     protected Layout<String> createJsonLayout() {
-        return JsonLayout.createLayout("true", "true", "false", "false", null);
+        return JsonLayout.createLayout(true, true, false, false, null);
     }
 
     protected abstract Layout<? extends Serializable> createLayout();
@@ -173,7 +173,7 @@ public abstract class AbstractSocketServ
         socketAppender.start();
         final ListAppender listAppender = new ListAppender("Events", serverFilter, null, false, false);
         listAppender.start();
-        final PatternLayout layout = PatternLayout.createLayout("%m %ex%n", null, null, null, null, null, null, null);
+        final PatternLayout layout = PatternLayout.createCustomLayout("%m %ex%n");
         final ConsoleAppender console = ConsoleAppender.createAppender(layout, null, "SYSTEM_OUT", "Console", "false",
                 "true");
         final Logger serverLogger = ctx.getLogger(this.getClass().getName());