You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by vy...@apache.org on 2020/11/19 15:56:24 UTC

[logging-log4j2] branch release-2.x updated (1c340db -> 6cb2872)

This is an automated email from the ASF dual-hosted git repository.

vy pushed a change to branch release-2.x
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git.


 discard 1c340db  Align JSON template layout code base with master.
     new 6cb2872  Align JSON template layout code base with master.

This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version.  This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:

 * -- * -- B -- O -- O -- O   (1c340db)
            \
             N -- N -- N   refs/heads/release-2.x (6cb2872)

You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.

Any revisions marked "omit" are not gone; other references still
refer to them.  Any revisions marked "discard" are gone forever.

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 log4j-layout-template-json/revapi.json | 10 ++++++++++
 1 file changed, 10 insertions(+)


[logging-log4j2] 01/01: Align JSON template layout code base with master.

Posted by vy...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

vy pushed a commit to branch release-2.x
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git

commit 6cb2872de59add3e79ed0dd227bf05a699989020
Author: Volkan Yazici <vo...@gmail.com>
AuthorDate: Thu Nov 19 15:26:21 2020 +0100

    Align JSON template layout code base with master.
---
 log4j-layout-template-json/pom.xml                 |  51 +++---
 log4j-layout-template-json/revapi.json             |  10 ++
 .../template/json/JsonTemplateLayoutDefaults.java  | 178 ++++++---------------
 .../template/json/resolver/ExceptionResolver.java  |   2 +-
 .../template/json/resolver/TemplateResolver.java   |  27 ++++
 .../layout/template/json/util/JsonWriterTest.java  |   2 -
 6 files changed, 119 insertions(+), 151 deletions(-)

diff --git a/log4j-layout-template-json/pom.xml b/log4j-layout-template-json/pom.xml
index e9a46a3..a2fce5f 100644
--- a/log4j-layout-template-json/pom.xml
+++ b/log4j-layout-template-json/pom.xml
@@ -383,18 +383,19 @@
                         <arg>1</arg>
                         <arg>-e</arg>
                         <arg>
+                          <![CDATA[
                           input {
                             gelf {
-                              host =&gt; "logstash"
-                              use_tcp =&gt; true
-                              use_udp =&gt; false
-                              port =&gt; 12222
-                              type =&gt; "gelf"
+                              host => "logstash"
+                              use_tcp => true
+                              use_udp => false
+                              port => 12222
+                              type => "gelf"
                             }
                             tcp {
-                              port =&gt; 12345
-                              codec =&gt; json
-                              type =&gt; "tcp"
+                              port => 12345
+                              codec => json
+                              type => "tcp"
                             }
                           }
 
@@ -403,17 +404,17 @@
                               # These are GELF/Syslog logging levels as defined in RFC 3164.
                               # Map the integer level to its human readable format.
                               translate {
-                                field =&gt; "[level]"
-                                destination =&gt; "[levelName]"
-                                dictionary =&gt; {
-                                  "0" =&gt; "EMERG"
-                                  "1" =&gt; "ALERT"
-                                  "2" =&gt; "CRITICAL"
-                                  "3" =&gt; "ERROR"
-                                  "4" =&gt; "WARN"
-                                  "5" =&gt; "NOTICE"
-                                  "6" =&gt; "INFO"
-                                  "7" =&gt; "DEBUG"
+                                field => "[level]"
+                                destination => "[levelName]"
+                                dictionary => {
+                                  "0" => "EMERG"
+                                  "1" => "ALERT"
+                                  "2" => "CRITICAL"
+                                  "3" => "ERROR"
+                                  "4" => "WARN"
+                                  "5" => "NOTICE"
+                                  "6" => "INFO"
+                                  "7" => "DEBUG"
                                 }
                               }
                             }
@@ -421,12 +422,13 @@
 
                           output {
                             # (Un)comment for debugging purposes
-                            # stdout { codec =&gt; rubydebug }
+                            # stdout { codec => rubydebug }
                             elasticsearch {
-                              hosts =&gt; ["http://elasticsearch:9200"]
-                              index =&gt; "log4j"
+                              hosts => ["http://elasticsearch:9200"]
+                              index => "log4j"
                             }
                           }
+                          ]]>
                         </arg>
                       </exec>
                     </entrypoint>
@@ -501,6 +503,11 @@
       </plugin>
 
       <plugin>
+        <groupId>com.github.spotbugs</groupId>
+        <artifactId>spotbugs-maven-plugin</artifactId>
+      </plugin>
+
+      <plugin>
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-jxr-plugin</artifactId>
         <version>${jxr.plugin.version}</version>
diff --git a/log4j-layout-template-json/revapi.json b/log4j-layout-template-json/revapi.json
index 20bd8ed..c24b6fc 100644
--- a/log4j-layout-template-json/revapi.json
+++ b/log4j-layout-template-json/revapi.json
@@ -32,6 +32,16 @@
         "code": "java.class.removed",
         "old": "class org.apache.logging.log4j.layout.template.json.JsonTemplateLayout.EventTemplateAdditionalFields",
         "justification": "LOG4J2-2961 Refactored for simplicity since it was already broken due to missing @PluginBuilderAttribute annotations"
+      },
+      {
+        "code": "java.method.removed",
+        "old": "method java.lang.String org.apache.logging.log4j.layout.template.json.JsonTemplateLayoutDefaults::getMdcKeyPattern()",
+        "justification": "Removed unused property getter."
+      },
+      {
+        "code": "java.method.removed",
+        "old": "method java.lang.String org.apache.logging.log4j.layout.template.json.JsonTemplateLayoutDefaults::getNdcPattern()",
+        "justification": "Removed unused property getter."
       }
     ]
   }
diff --git a/log4j-layout-template-json/src/main/java/org/apache/logging/log4j/layout/template/json/JsonTemplateLayoutDefaults.java b/log4j-layout-template-json/src/main/java/org/apache/logging/log4j/layout/template/json/JsonTemplateLayoutDefaults.java
index 9896c1e..4f417ee 100644
--- a/log4j-layout-template-json/src/main/java/org/apache/logging/log4j/layout/template/json/JsonTemplateLayoutDefaults.java
+++ b/log4j-layout-template-json/src/main/java/org/apache/logging/log4j/layout/template/json/JsonTemplateLayoutDefaults.java
@@ -29,71 +29,7 @@ public enum JsonTemplateLayoutDefaults {;
 
     private static final PropertiesUtil PROPERTIES = PropertiesUtil.getProperties();
 
-    private static final Charset CHARSET = readCharset();
-
-    private static final boolean LOCATION_INFO_ENABLED =
-            PROPERTIES.getBooleanProperty(
-                    "log4j.layout.jsonTemplate.locationInfoEnabled",
-                    false);
-
-    private static final boolean STACK_TRACE_ENABLED =
-            PROPERTIES.getBooleanProperty(
-                    "log4j.layout.jsonTemplate.stackTraceEnabled",
-                    true);
-
-    private static final String TIMESTAMP_FORMAT_PATTERN =
-            PROPERTIES.getStringProperty(
-                    "log4j.layout.jsonTemplate.timestampFormatPattern",
-                    "yyyy-MM-dd'T'HH:mm:ss.SSSZZZ");
-
-    private static final TimeZone TIME_ZONE = readTimeZone();
-
-    private static final Locale LOCALE = readLocale();
-
-    private static final String EVENT_TEMPLATE =
-            PROPERTIES.getStringProperty(
-                    "log4j.layout.jsonTemplate.eventTemplate");
-
-    private static final String EVENT_TEMPLATE_URI =
-            PROPERTIES.getStringProperty(
-                    "log4j.layout.jsonTemplate.eventTemplateUri",
-                    "classpath:EcsLayout.json");
-
-    private static final String STACK_TRACE_ELEMENT_TEMPLATE =
-            PROPERTIES.getStringProperty(
-                    "log4j.layout.jsonTemplate.stackTraceElementTemplate");
-
-    private static final String STACK_TRACE_ELEMENT_TEMPLATE_URI =
-            PROPERTIES.getStringProperty(
-                    "log4j.layout.jsonTemplate.stackTraceElementTemplateUri",
-                    "classpath:StackTraceElementLayout.json");
-
-    private static final String MDC_KEY_PATTERN =
-            PROPERTIES.getStringProperty("log4j.layout.jsonTemplate.mdcKeyPattern");
-
-    private static final String NDC_PATTERN =
-            PROPERTIES.getStringProperty("log4j.layout.jsonTemplate.ndcPattern");
-
-    private static final String EVENT_DELIMITER =
-            PROPERTIES.getStringProperty(
-                    "log4j.layout.jsonTemplate.eventDelimiter",
-                    System.lineSeparator());
-
-    private static final boolean NULL_EVENT_DELIMITER_ENABLED =
-            PROPERTIES.getBooleanProperty(
-                    "log4j.layout.jsonTemplate.nullEventDelimiterEnabled",
-                    false);
-
-    private static final int MAX_STRING_LENGTH = readMaxStringLength();
-
-    private static final String TRUNCATED_STRING_SUFFIX =
-            PROPERTIES.getStringProperty(
-                    "log4j.layout.jsonTemplate.truncatedStringSuffix",
-                    "…");
-
-    private static final RecyclerFactory RECYCLER_FACTORY = readRecyclerFactory();
-
-    private static Charset readCharset() {
+    public static Charset getCharset() {
         final String charsetName =
                 PROPERTIES.getStringProperty("log4j.layout.jsonTemplate.charset");
         return charsetName != null
@@ -101,7 +37,25 @@ public enum JsonTemplateLayoutDefaults {;
                 : StandardCharsets.UTF_8;
     }
 
-    private static TimeZone readTimeZone() {
+    public static boolean isLocationInfoEnabled() {
+        return PROPERTIES.getBooleanProperty(
+                "log4j.layout.jsonTemplate.locationInfoEnabled",
+                false);
+    }
+
+    public static boolean isStackTraceEnabled() {
+        return PROPERTIES.getBooleanProperty(
+                "log4j.layout.jsonTemplate.stackTraceEnabled",
+                true);
+    }
+
+    public static String getTimestampFormatPattern() {
+        return PROPERTIES.getStringProperty(
+                "log4j.layout.jsonTemplate.timestampFormatPattern",
+                "yyyy-MM-dd'T'HH:mm:ss.SSSZZZ");
+    }
+
+    public static TimeZone getTimeZone() {
         final String timeZoneId =
                 PROPERTIES.getStringProperty("log4j.layout.jsonTemplate.timeZone");
         return timeZoneId != null
@@ -109,7 +63,7 @@ public enum JsonTemplateLayoutDefaults {;
                 : TimeZone.getDefault();
     }
 
-    private static Locale readLocale() {
+    public static Locale getLocale() {
         final String locale =
                 PROPERTIES.getStringProperty("log4j.layout.jsonTemplate.locale");
         if (locale == null) {
@@ -124,90 +78,62 @@ public enum JsonTemplateLayoutDefaults {;
         }
     }
 
-    private static int readMaxStringLength() {
-        final int maxStringLength = PROPERTIES.getIntegerProperty(
-                "log4j.layout.jsonTemplate.maxStringLength",
-                16 * 1_024);
-        if (maxStringLength <= 0) {
-            throw new IllegalArgumentException(
-                    "was expecting a non-zero positive maxStringLength: " +
-                            maxStringLength);
-        }
-        return maxStringLength;
-    }
-
-    private static RecyclerFactory readRecyclerFactory() {
-        final String recyclerFactorySpec = PROPERTIES.getStringProperty(
-                "log4j.layout.jsonTemplate.recyclerFactory");
-        return RecyclerFactories.ofSpec(recyclerFactorySpec);
-    }
-
-    public static Charset getCharset() {
-        return CHARSET;
-    }
-
-    public static boolean isLocationInfoEnabled() {
-        return LOCATION_INFO_ENABLED;
-    }
-
-    public static boolean isStackTraceEnabled() {
-        return STACK_TRACE_ENABLED;
-    }
-
-    public static String getTimestampFormatPattern() {
-        return TIMESTAMP_FORMAT_PATTERN;
-    }
-
-    public static TimeZone getTimeZone() {
-        return TIME_ZONE;
-    }
-
-    public static Locale getLocale() {
-        return LOCALE;
-    }
-
     public static String getEventTemplate() {
-        return EVENT_TEMPLATE;
+        return PROPERTIES.getStringProperty(
+                "log4j.layout.jsonTemplate.eventTemplate");
     }
 
     public static String getEventTemplateUri() {
-        return EVENT_TEMPLATE_URI;
+        return PROPERTIES.getStringProperty(
+                "log4j.layout.jsonTemplate.eventTemplateUri",
+                "classpath:EcsLayout.json");
     }
 
     public static String getStackTraceElementTemplate() {
-        return STACK_TRACE_ELEMENT_TEMPLATE;
+        return PROPERTIES.getStringProperty(
+                "log4j.layout.jsonTemplate.stackTraceElementTemplate");
     }
 
     public static String getStackTraceElementTemplateUri() {
-        return STACK_TRACE_ELEMENT_TEMPLATE_URI;
-    }
-
-    public static String getMdcKeyPattern() {
-        return MDC_KEY_PATTERN;
-    }
-
-    public static String getNdcPattern() {
-        return NDC_PATTERN;
+        return PROPERTIES.getStringProperty(
+                "log4j.layout.jsonTemplate.stackTraceElementTemplateUri",
+                "classpath:StackTraceElementLayout.json");
     }
 
     public static String getEventDelimiter() {
-        return EVENT_DELIMITER;
+        return PROPERTIES.getStringProperty(
+                "log4j.layout.jsonTemplate.eventDelimiter",
+                System.lineSeparator());
     }
 
     public static boolean isNullEventDelimiterEnabled() {
-        return NULL_EVENT_DELIMITER_ENABLED;
+        return PROPERTIES.getBooleanProperty(
+                "log4j.layout.jsonTemplate.nullEventDelimiterEnabled",
+                false);
     }
 
     public static int getMaxStringLength() {
-        return MAX_STRING_LENGTH;
+        final int maxStringLength = PROPERTIES.getIntegerProperty(
+                "log4j.layout.jsonTemplate.maxStringLength",
+                16 * 1_024);
+        if (maxStringLength <= 0) {
+            throw new IllegalArgumentException(
+                    "was expecting a non-zero positive maxStringLength: " +
+                            maxStringLength);
+        }
+        return maxStringLength;
     }
 
     public static String getTruncatedStringSuffix() {
-        return TRUNCATED_STRING_SUFFIX;
+        return PROPERTIES.getStringProperty(
+                "log4j.layout.jsonTemplate.truncatedStringSuffix",
+                "…");
     }
 
     public static RecyclerFactory getRecyclerFactory() {
-        return RECYCLER_FACTORY;
+        final String recyclerFactorySpec = PROPERTIES.getStringProperty(
+                "log4j.layout.jsonTemplate.recyclerFactory");
+        return RecyclerFactories.ofSpec(recyclerFactorySpec);
     }
 
 }
diff --git a/log4j-layout-template-json/src/main/java/org/apache/logging/log4j/layout/template/json/resolver/ExceptionResolver.java b/log4j-layout-template-json/src/main/java/org/apache/logging/log4j/layout/template/json/resolver/ExceptionResolver.java
index 4cd9b62..415104a 100644
--- a/log4j-layout-template-json/src/main/java/org/apache/logging/log4j/layout/template/json/resolver/ExceptionResolver.java
+++ b/log4j-layout-template-json/src/main/java/org/apache/logging/log4j/layout/template/json/resolver/ExceptionResolver.java
@@ -22,7 +22,7 @@ import org.apache.logging.log4j.layout.template.json.util.JsonWriter;
 
 /**
  * Exception resolver.
- *
+ * <p>
  * Note that this resolver is toggled by {@link
  * JsonTemplateLayout.Builder#setStackTraceEnabled(boolean)}.
  *
diff --git a/log4j-layout-template-json/src/main/java/org/apache/logging/log4j/layout/template/json/resolver/TemplateResolver.java b/log4j-layout-template-json/src/main/java/org/apache/logging/log4j/layout/template/json/resolver/TemplateResolver.java
index 5db3813..62ce41d 100644
--- a/log4j-layout-template-json/src/main/java/org/apache/logging/log4j/layout/template/json/resolver/TemplateResolver.java
+++ b/log4j-layout-template-json/src/main/java/org/apache/logging/log4j/layout/template/json/resolver/TemplateResolver.java
@@ -21,20 +21,47 @@ import org.apache.logging.log4j.layout.template.json.util.JsonWriter;
 @FunctionalInterface
 public interface TemplateResolver<V> {
 
+    /**
+     * Indicates if the resolution should be appended to the parent JSON object.
+     * <p>
+     * For instance, {@link ThreadContextDataResolver}, i.e., MDC resolver,
+     * uses this flag to indicate whether the contents should be appended to the
+     * parent JSON object or not.
+     */
     default boolean isFlattening() {
         return false;
     }
 
+    /**
+     * Indicates if the resolver if applicable at all.
+     * <p>
+     * For instance, the source line resolver can be short-circuited using this
+     * check if the location information is disabled in the layout configuration.
+     */
     default boolean isResolvable() {
         return true;
     }
 
+    /**
+     * Indicates if the resolver if applicable for the given {@code value}.
+     * <p>
+     * For instance, the stack trace resolver can be short-circuited using this
+     * check if the stack traces are disabled in the layout configuration.
+     */
     default boolean isResolvable(V value) {
         return true;
     }
 
+    /**
+     * Resolves the given {@code value} using the provided {@link JsonWriter}.
+     */
     void resolve(V value, JsonWriter jsonWriter);
 
+    /**
+     * Resolves the given {@code value} using the provided {@link JsonWriter}.
+     *
+     * @param succeedingEntry false, if this is the first element in a collection; true, otherwise
+     */
     default void resolve(V value, JsonWriter jsonWriter, boolean succeedingEntry) {
         resolve(value, jsonWriter);
     }
diff --git a/log4j-layout-template-json/src/test/java/org/apache/logging/log4j/layout/template/json/util/JsonWriterTest.java b/log4j-layout-template-json/src/test/java/org/apache/logging/log4j/layout/template/json/util/JsonWriterTest.java
index 68fe638..def4d42 100644
--- a/log4j-layout-template-json/src/test/java/org/apache/logging/log4j/layout/template/json/util/JsonWriterTest.java
+++ b/log4j-layout-template-json/src/test/java/org/apache/logging/log4j/layout/template/json/util/JsonWriterTest.java
@@ -375,7 +375,6 @@ public class JsonWriterTest {
     @Test
     public void test_writeString_formattable() {
         final String expectedJson = "\"foo\\tbar\\tbuzz\"";
-        @SuppressWarnings("Convert2Lambda")
         final String actualJson = WRITER.use(() ->
                 WRITER.writeString(stringBuilder -> stringBuilder.append("foo\tbar\tbuzz")));
         Assertions.assertThat(actualJson).isEqualTo(expectedJson);
@@ -389,7 +388,6 @@ public class JsonWriterTest {
                 excessiveString.substring(0, maxStringLength) +
                 WRITER.getTruncatedStringSuffix() +
                 '"';
-        @SuppressWarnings("Convert2Lambda")
         final String actualJson = WRITER.use(() ->
                 WRITER.writeString(stringBuilder -> stringBuilder.append(excessiveString)));
         Assertions.assertThat(actualJson).isEqualTo(expectedJson);