From f3fedc2e69e202a4e4d6387ca8402a992816a731 Mon Sep 17 00:00:00 2001
From: Ceki Gulcu
Date: Fri, 22 Dec 2023 16:22:56 +0100
Subject: [PATCH] add kv() methods as synonyms for addKeyValue(), add kv()
catering for primitives
Signed-off-by: Ceki Gulcu
---
.../org/slf4j/spi/LoggingEventBuilder.java | 232 ++++++++++++--
.../org/slf4j/spi/NOPLoggingEventBuilder.java | 302 +++++++++++++++---
2 files changed, 471 insertions(+), 63 deletions(-)
diff --git a/slf4j-api/src/main/java/org/slf4j/spi/LoggingEventBuilder.java b/slf4j-api/src/main/java/org/slf4j/spi/LoggingEventBuilder.java
index cd48e4422..e3af848f5 100755
--- a/slf4j-api/src/main/java/org/slf4j/spi/LoggingEventBuilder.java
+++ b/slf4j-api/src/main/java/org/slf4j/spi/LoggingEventBuilder.java
@@ -43,7 +43,7 @@ public interface LoggingEventBuilder {
/**
* Set the cause for the logging event being built.
* @param cause a throwable
- * @return a LoggingEventBuilder, usually this.
+ * @return a LoggingEventBuilder instance, usually this.
*/
@CheckReturnValue
LoggingEventBuilder setCause(Throwable cause);
@@ -52,27 +52,27 @@ public interface LoggingEventBuilder {
* A {@link Marker marker} to the event being built.
*
* @param marker a Marker instance to add.
- * @return a LoggingEventBuilder, usually this.
+ * @return a LoggingEventBuilder instance, usually this.
*/
@CheckReturnValue
LoggingEventBuilder addMarker(Marker marker);
/**
* Add an argument to the event being built.
- * Synonymous with {@link #arg(Object)}.
+ * Synonymous with {@link #arg(Object)} method.
*
* @param p an Object to add.
- * @return a LoggingEventBuilder, usually this.
+ * @return a LoggingEventBuilder instance, usually this.
*/
@CheckReturnValue
LoggingEventBuilder addArgument(Object p);
/**
* Add an argument to the event being built.
- * Synonymous with {@link #addArgument(Object)}.
+ * Synonymous with {@link #addArgument(Object)} method.
*
* @param p an Object to add.
- * @return a LoggingEventBuilder, usually this.
+ * @return a LoggingEventBuilder instance, usually this.
* @since 2.1.0
*/
@CheckReturnValue
@@ -81,10 +81,11 @@ default LoggingEventBuilder arg(Object p) {
}
/**
- *
Add an argument supplier to the event being built. Synonymous with {@link #arg(Supplier)}.
+ *
Add an argument supplier to the event being built.
+ * Synonymous with {@link #arg(Supplier)} method.
*
* @param objectSupplier an Object supplier to add.
- * @return a LoggingEventBuilder, usually this.
+ * @return a LoggingEventBuilder instance, usually this.
*/
@CheckReturnValue
LoggingEventBuilder addArgument(Supplier> objectSupplier);
@@ -92,11 +93,11 @@ default LoggingEventBuilder arg(Object p) {
/**
*
Add an argument supplier to the event being built.
- * Synonymous with {@link #addArgument(Supplier)}.
+ * Synonymous with {@link #addArgument(Supplier)} method.
*
*
* @param objectSupplier an Object supplier to add.
- * @return a LoggingEventBuilder, usually this.
+ * @return a LoggingEventBuilder instance, usually this.
* @since 2.1.0
*/
@CheckReturnValue
@@ -111,7 +112,7 @@ default LoggingEventBuilder arg(Supplier> objectSupplier) {
* {@link NOPLoggingEventBuilder}, skips the cast.
*
* @param b a value of type boolean value to add.
- * @return a LoggingEventBuilder, usually this.
+ * @return a LoggingEventBuilder instance, usually this.
* @since 2.1.0
*/
default public LoggingEventBuilder arg(boolean b) {
@@ -125,7 +126,7 @@ default public LoggingEventBuilder arg(boolean b) {
* {@link NOPLoggingEventBuilder}, skips the cast.
*
* @param c a value of type char value to add.
- * @return a LoggingEventBuilder, usually this.
+ * @return a LoggingEventBuilder instance, usually this.
* @since 2.1.0
*/
default public LoggingEventBuilder arg(char c) {
@@ -139,7 +140,7 @@ default public LoggingEventBuilder arg(char c) {
* {@link NOPLoggingEventBuilder}, skips the cast.
*
* @param b a value of type byte value to add.
- * @return a LoggingEventBuilder, usually this.
+ * @return a LoggingEventBuilder instance, usually this.
* @since 2.1.0
*/
default public LoggingEventBuilder arg(byte b) {
@@ -153,7 +154,7 @@ default public LoggingEventBuilder arg(byte b) {
* {@link NOPLoggingEventBuilder}, skips the cast.
*
* @param s a value of type short value to add.
- * @return a LoggingEventBuilder, usually this.
+ * @return a LoggingEventBuilder instance, usually this.
* @since 2.1.0
*/
default public LoggingEventBuilder arg(short s) {
@@ -167,7 +168,7 @@ default public LoggingEventBuilder arg(short s) {
* {@link NOPLoggingEventBuilder}, skips the cast.
*
* @param i a value of type int value to add.
- * @return a LoggingEventBuilder, usually this.
+ * @return a LoggingEventBuilder instance, usually this.
* @since 2.1.0
*/
default public LoggingEventBuilder arg(int i) {
@@ -181,7 +182,7 @@ default public LoggingEventBuilder arg(int i) {
* {@link NOPLoggingEventBuilder}, skips the cast.
*
* @param l a value of type long value to add.
- * @return a LoggingEventBuilder, usually this.
+ * @return a LoggingEventBuilder instance, usually this.
* @since 2.1.0
*/
default public LoggingEventBuilder arg(long l) {
@@ -195,7 +196,7 @@ default public LoggingEventBuilder arg(long l) {
* {@link NOPLoggingEventBuilder}, skips the cast.
*
* @param f a value of type float value to add.
- * @return a LoggingEventBuilder, usually this.
+ * @return a LoggingEventBuilder instance, usually this.
* @since 2.1.0
*/
default public LoggingEventBuilder arg(float f) {
@@ -208,7 +209,7 @@ default public LoggingEventBuilder arg(float f) {
*
The default implementation simply casts to Double. However, the NOP implementation skips the cast.
*
* @param d a value of type double value to add.
- * @return a LoggingEventBuilder, usually this.
+ * @return a LoggingEventBuilder instance, usually this.
* @since 2.1.0
*/
default LoggingEventBuilder arg(double d) {
@@ -221,25 +222,213 @@ default LoggingEventBuilder arg(double d) {
*
* @param key the key of the key value pair.
* @param value the value of the key value pair.
- * @return a LoggingEventBuilder, usually this.
+ * @return a LoggingEventBuilder instance, usually this.
*/
@CheckReturnValue
LoggingEventBuilder addKeyValue(String key, Object value);
+ /**
+ * Add a {@link org.slf4j.event.KeyValuePair key value pair} to the event being built.
+ * Synonymous with {@link #addKeyValue(String, Object)} method.
+ *
+ * @param key the key of the key value pair.
+ * @param value the value of the key value pair.
+ * @return a LoggingEventBuilder instance, usually this.
+ *
+ * @since 2.1.0
+ */
+ @CheckReturnValue
+ default LoggingEventBuilder kv(String key, Object value) {
+ return addKeyValue(key,value);
+ }
+
+
/**
* Add a {@link org.slf4j.event.KeyValuePair key value pair} to the event being built.
*
* @param key the key of the key value pair.
* @param valueSupplier a supplier of a value for the key value pair.
- * @return a LoggingEventBuilder, usually this.
+ * @return a LoggingEventBuilder instance, usually this.
*/
@CheckReturnValue
LoggingEventBuilder addKeyValue(String key, Supplier