You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by rg...@apache.org on 2021/03/05 06:13:19 UTC

[logging-log4j2] branch master updated: LOG4J2-2947 - Mention default methods do nothing. Add log method with no parameters.

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

rgoers pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git


The following commit(s) were added to refs/heads/master by this push:
     new e4cdfd2  LOG4J2-2947 - Mention default methods do nothing. Add log method with no parameters.
e4cdfd2 is described below

commit e4cdfd25680489fd028e37c04a8ab1a363f23f41
Author: Ralph Goers <rg...@apache.org>
AuthorDate: Thu Mar 4 23:13:03 2021 -0700

    LOG4J2-2947 - Mention default methods do nothing. Add log method with no parameters.
---
 .../java/org/apache/logging/log4j/LogBuilder.java  | 73 ++++++++++++++++++----
 .../logging/log4j/internal/DefaultLogBuilder.java  |  9 +++
 2 files changed, 71 insertions(+), 11 deletions(-)

diff --git a/log4j-api/src/main/java/org/apache/logging/log4j/LogBuilder.java b/log4j-api/src/main/java/org/apache/logging/log4j/LogBuilder.java
index 0119688..d62ef25 100644
--- a/log4j-api/src/main/java/org/apache/logging/log4j/LogBuilder.java
+++ b/log4j-api/src/main/java/org/apache/logging/log4j/LogBuilder.java
@@ -28,30 +28,58 @@ public interface LogBuilder {
 
     public static final LogBuilder NOOP = new LogBuilder() {};
 
+    /**
+     * Includes a Marker in the log event. Interface default method does nothing.
+     * @param marker The Marker to log.
+     * @return The LogBuilder.
+     */
     default LogBuilder withMarker(Marker marker) {
         return this;
     }
 
+    /**
+     * Includes a Throwable in the log event. Interface default method does nothing.
+     * @param throwable The Throwable to log.
+     * @return the LogBuilder.
+     */
     default LogBuilder withThrowable(Throwable throwable) {
         return this;
     }
 
+    /**
+     * An implementation will calculate the caller's stack frame and include it in the log event.
+     * Interface default method does nothing.
+     * @return The LogBuilder.
+     */
     default LogBuilder withLocation() {
         return this;
     }
 
+    /**
+     * Adds the specified stack trace element to the log event. Interface default method does nothing.
+     * @param location The stack trace element to include in the log event.
+     * @return The LogBuilder.
+     */
     default LogBuilder withLocation(StackTraceElement location) {
         return this;
     }
 
+    /**
+     * Causes all the data collected to be logged along with the message. Interface default method does nothing.
+     * @param message The message to log.
+     */
     default void log(CharSequence message) {
     }
 
+    /**
+     * Causes all the data collected to be logged along with the message. Interface default method does nothing.
+     * @param message The message to log.
+     */
     default void log(String message) {
     }
 
     /**
-     * Logs a message with parameters.
+     * Logs a message with parameters. Interface default method does nothing.
      *
      * @param message the message to log; the format depends on the message factory.
      * @param params parameters to the message.
@@ -61,21 +89,38 @@ public interface LogBuilder {
     default void log(String message, Object... params) {
     }
 
+    /**
+     * Causes all the data collected to be logged along with the message and parameters.
+     * Interface default method does nothing.
+     * @param message The message.
+     * @param params Parameters to the message.
+     */
     default void log(String message, Supplier<?>... params) {
     }
 
+    /**
+     * Causes all the data collected to be logged along with the message. Interface default method does nothing.
+     * @param message The message to log.
+     */
     default void log(Message message) {
     }
 
+    /**
+     * Causes all the data collected to be logged along with the message. Interface default method does nothing.
+     * @param messageSupplier The supplier of the message to log.
+     */
     default void log(Supplier<Message> messageSupplier) {
     }
 
+    /**
+     * Causes all the data collected to be logged along with the message. Interface default method does nothing.
+     * @param message The message to log.
+     */
     default void log(Object message) {
-
     }
 
     /**
-     * Logs a message with parameters.
+     * Logs a message with parameters. Interface default method does nothing.
      *
      * @param message the message to log; the format depends on the message factory.
      * @param p0 parameter to the message.
@@ -86,7 +131,7 @@ public interface LogBuilder {
     }
 
     /**
-     * Logs a message with parameters.
+     * Logs a message with parameters. Interface default method does nothing.
      *
      * @param message the message to log; the format depends on the message factory.
      * @param p0 parameter to the message.
@@ -98,7 +143,7 @@ public interface LogBuilder {
     }
 
     /**
-     * Logs a message with parameters.
+     * Logs a message with parameters. Interface default method does nothing.
      *
      * @param message the message to log; the format depends on the message factory.
      * @param p0 parameter to the message.
@@ -111,7 +156,7 @@ public interface LogBuilder {
     }
 
     /**
-     * Logs a message with parameters.
+     * Logs a message with parameters. Interface default method does nothing.
      *
      * @param message the message to log; the format depends on the message factory.
      * @param p0 parameter to the message.
@@ -125,7 +170,7 @@ public interface LogBuilder {
     }
 
     /**
-     * Logs a message with parameters.
+     * Logs a message with parameters. Interface default method does nothing.
      *
      * @param message the message to log; the format depends on the message factory.
      * @param p0 parameter to the message.
@@ -140,7 +185,7 @@ public interface LogBuilder {
     }
 
     /**
-     * Logs a message with parameters.
+     * Logs a message with parameters. Interface default method does nothing.
      *
      * @param message the message to log; the format depends on the message factory.
      * @param p0 parameter to the message.
@@ -173,7 +218,7 @@ public interface LogBuilder {
     }
 
     /**
-     * Logs a message with parameters.
+     * Logs a message with parameters. Interface default method does nothing.
      *
      * @param message the message to log; the format depends on the message factory.
      * @param p0 parameter to the message.
@@ -192,7 +237,7 @@ public interface LogBuilder {
     }
 
     /**
-     * Logs a message with parameters.
+     * Logs a message with parameters. Interface default method does nothing.
      *
      * @param message the message to log; the format depends on the message factory.
      * @param p0 parameter to the message.
@@ -212,7 +257,7 @@ public interface LogBuilder {
     }
 
     /**
-     * Logs a message with parameters.
+     * Logs a message with parameters. Interface default method does nothing.
      *
      * @param message the message to log; the format depends on the message factory.
      * @param p0 parameter to the message.
@@ -231,4 +276,10 @@ public interface LogBuilder {
     default void log(String message, Object p0, Object p1, Object p2, Object p3, Object p4, Object p5, Object p6,
             Object p7, Object p8, Object p9) {
     }
+
+    /**
+     * Causes all the data collected to be logged. Default implementatoin does nothing.
+     */
+    default void log() {
+    }
 }
diff --git a/log4j-api/src/main/java/org/apache/logging/log4j/internal/DefaultLogBuilder.java b/log4j-api/src/main/java/org/apache/logging/log4j/internal/DefaultLogBuilder.java
index 0be9215..f4243ac 100644
--- a/log4j-api/src/main/java/org/apache/logging/log4j/internal/DefaultLogBuilder.java
+++ b/log4j-api/src/main/java/org/apache/logging/log4j/internal/DefaultLogBuilder.java
@@ -25,6 +25,7 @@ import org.apache.logging.log4j.message.SimpleMessage;
 import org.apache.logging.log4j.status.StatusLogger;
 import org.apache.logging.log4j.util.LambdaUtil;
 import org.apache.logging.log4j.util.StackLocatorUtil;
+import org.apache.logging.log4j.util.Strings;
 import org.apache.logging.log4j.util.Supplier;
 
 
@@ -35,6 +36,7 @@ public class DefaultLogBuilder implements LogBuilder {
 
     private static final String FQCN = DefaultLogBuilder.class.getName();
     private static final Logger LOGGER = StatusLogger.getLogger();
+    private static final Message EMPTY_MESSAGE = new SimpleMessage(Strings.EMPTY);
 
     private final Logger logger;
     private Level level;
@@ -217,6 +219,13 @@ public class DefaultLogBuilder implements LogBuilder {
         }
     }
 
+    @Override
+    public void log() {
+        if (isValid()) {
+            logMessage(EMPTY_MESSAGE);
+        }
+    }
+
     private void logMessage(Message message) {
         try {
             logger.logMessage(level, marker, FQCN, location, message, throwable);