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:31 UTC
[logging-log4j2] branch release-2.x 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 release-2.x
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git
The following commit(s) were added to refs/heads/release-2.x by this push:
new bc306a3 LOG4J2-2947 - Mention default methods do nothing. Add log method with no parameters.
bc306a3 is described below
commit bc306a3b075f083b4575ca68984d1753d430a3c7
Author: Ralph Goers <rg...@apache.org>
AuthorDate: Thu Mar 4 23:11:48 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 | 7 +++
2 files changed, 69 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 9ac592d..63b77a1 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
@@ -222,6 +222,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);