Skip to content

Commit

Permalink
add kv() methods as synonyms for addKeyValue(), add kv() catering for…
Browse files Browse the repository at this point in the history
… primitives

Signed-off-by: Ceki Gulcu <ceki@qos.ch>
  • Loading branch information
ceki committed Dec 22, 2023
1 parent 8a72658 commit f3fedc2
Show file tree
Hide file tree
Showing 2 changed files with 471 additions and 63 deletions.
232 changes: 211 additions & 21 deletions slf4j-api/src/main/java/org/slf4j/spi/LoggingEventBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public interface LoggingEventBuilder {
/**
* Set the cause for the logging event being built.
* @param cause a throwable
* @return a LoggingEventBuilder, usually <b>this</b>.
* @return a LoggingEventBuilder instance, usually <b>this</b>.
*/
@CheckReturnValue
LoggingEventBuilder setCause(Throwable cause);
Expand All @@ -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 <b>this</b>.
* @return a LoggingEventBuilder instance, usually <b>this</b>.
*/
@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 <b>this</b>.
* @return a LoggingEventBuilder instance, usually <b>this</b>.
*/
@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 <b>this</b>.
* @return a LoggingEventBuilder instance, usually <b>this</b>.
* @since 2.1.0
*/
@CheckReturnValue
Expand All @@ -81,22 +81,23 @@ default LoggingEventBuilder arg(Object p) {
}

/**
* <p>Add an argument supplier to the event being built. Synonymous with {@link #arg(Supplier)}.
* <p>Add an argument supplier to the event being built.
* Synonymous with {@link #arg(Supplier)} method.
* </p>
* @param objectSupplier an Object supplier to add.
* @return a LoggingEventBuilder, usually <b>this</b>.
* @return a LoggingEventBuilder instance, usually <b>this</b>.
*/
@CheckReturnValue
LoggingEventBuilder addArgument(Supplier<?> objectSupplier);


/**
* <p>Add an argument supplier to the event being built.
* Synonymous with {@link #addArgument(Supplier)}.
* Synonymous with {@link #addArgument(Supplier)} method.
* </p>
*
* @param objectSupplier an Object supplier to add.
* @return a LoggingEventBuilder, usually <b>this</b>.
* @return a LoggingEventBuilder instance, usually <b>this</b>.
* @since 2.1.0
*/
@CheckReturnValue
Expand All @@ -111,7 +112,7 @@ default LoggingEventBuilder arg(Supplier<?> objectSupplier) {
* {@link NOPLoggingEventBuilder}, skips the cast.</p>
*
* @param b a value of type <code>boolean</code> value to add.
* @return a LoggingEventBuilder, usually <b>this</b>.
* @return a LoggingEventBuilder instance, usually <b>this</b>.
* @since 2.1.0
*/
default public LoggingEventBuilder arg(boolean b) {
Expand All @@ -125,7 +126,7 @@ default public LoggingEventBuilder arg(boolean b) {
* {@link NOPLoggingEventBuilder}, skips the cast.</p>
*
* @param c a value of type <code>char</code> value to add.
* @return a LoggingEventBuilder, usually <b>this</b>.
* @return a LoggingEventBuilder instance, usually <b>this</b>.
* @since 2.1.0
*/
default public LoggingEventBuilder arg(char c) {
Expand All @@ -139,7 +140,7 @@ default public LoggingEventBuilder arg(char c) {
* {@link NOPLoggingEventBuilder}, skips the cast.</p>
*
* @param b a value of type <code>byte</code> value to add.
* @return a LoggingEventBuilder, usually <b>this</b>.
* @return a LoggingEventBuilder instance, usually <b>this</b>.
* @since 2.1.0
*/
default public LoggingEventBuilder arg(byte b) {
Expand All @@ -153,7 +154,7 @@ default public LoggingEventBuilder arg(byte b) {
* {@link NOPLoggingEventBuilder}, skips the cast.</p>
*
* @param s a value of type <code>short</code> value to add.
* @return a LoggingEventBuilder, usually <b>this</b>.
* @return a LoggingEventBuilder instance, usually <b>this</b>.
* @since 2.1.0
*/
default public LoggingEventBuilder arg(short s) {
Expand All @@ -167,7 +168,7 @@ default public LoggingEventBuilder arg(short s) {
* {@link NOPLoggingEventBuilder}, skips the cast.</p>
*
* @param i a value of type <code>int</code> value to add.
* @return a LoggingEventBuilder, usually <b>this</b>.
* @return a LoggingEventBuilder instance, usually <b>this</b>.
* @since 2.1.0
*/
default public LoggingEventBuilder arg(int i) {
Expand All @@ -181,7 +182,7 @@ default public LoggingEventBuilder arg(int i) {
* {@link NOPLoggingEventBuilder}, skips the cast.</p>
*
* @param l a value of type <code>long</code> value to add.
* @return a LoggingEventBuilder, usually <b>this</b>.
* @return a LoggingEventBuilder instance, usually <b>this</b>.
* @since 2.1.0
*/
default public LoggingEventBuilder arg(long l) {
Expand All @@ -195,7 +196,7 @@ default public LoggingEventBuilder arg(long l) {
* {@link NOPLoggingEventBuilder}, skips the cast.</p>
*
* @param f a value of type <code>float</code> value to add.
* @return a LoggingEventBuilder, usually <b>this</b>.
* @return a LoggingEventBuilder instance, usually <b>this</b>.
* @since 2.1.0
*/
default public LoggingEventBuilder arg(float f) {
Expand All @@ -208,7 +209,7 @@ default public LoggingEventBuilder arg(float f) {
* <p>The default implementation simply casts to <code>Double</code>. However, the NOP implementation skips the cast.</p>
*
* @param d a value of type <code>double</code> value to add.
* @return a LoggingEventBuilder, usually <b>this</b>.
* @return a LoggingEventBuilder instance, usually <b>this</b>.
* @since 2.1.0
*/
default LoggingEventBuilder arg(double d) {
Expand All @@ -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 <b>this</b>.
* @return a LoggingEventBuilder instance, usually <b>this</b>.
*/
@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 <b>this</b>.
*
* @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 <b>this</b>.
* @return a LoggingEventBuilder instance, usually <b>this</b>.
*/
@CheckReturnValue
LoggingEventBuilder addKeyValue(String key, Supplier<Object> valueSupplier);

/**
* Add a {@link org.slf4j.event.KeyValuePair key value pair} to the event being built.
* Synonymous with {@link #addKeyValue(String, Supplier)} method.
*
* @param key the key of the key value pair.
* @param valueSupplier a supplier of a value for the key value pair.
* @return a LoggingEventBuilder instance, usually <b>this</b>.
*
* @since 2.1.0
*/
@CheckReturnValue
default LoggingEventBuilder kv(String key, Supplier<Object> valueSupplier) {
return addKeyValue(key, valueSupplier);
}


/**
* <p>Add a {@link org.slf4j.event.KeyValuePair key value pair} to the event being built, with the value part being
* of type <code>boolean</code>.
* </p>
* <p></p>
* <p>The default implementation simply casts to value part to <code>Boolean</code> before calling
* {@link #addKeyValue(String, Object)}. However, the
* NOP implementation, i.e {@link NOPLoggingEventBuilder}, skips the cast.</p>
*
* @param key the key of the key value pair.
* @param b the value of type <code>boolean</code> of the key value pair.
* @return a LoggingEventBuilder instance, usually <b>this</b>.
*
* @since 2.1.0
*/
default public LoggingEventBuilder kv(String key, boolean b) {
return addKeyValue(key, (Boolean) b);
}

/**
* <p>Add a {@link org.slf4j.event.KeyValuePair key value pair} to the event being built, with the value part being
* of type <code>char</code>.
* </p>
* <p></p>
* <p>The default implementation simply casts to value part to <code>Character</code> before calling
* {@link #addKeyValue(String, Object)}. However, the
* NOP implementation, i.e {@link NOPLoggingEventBuilder}, skips the cast.</p>
*
* @param key the key of the key value pair.
* @param c the value of type <code>char</code> of the key value pair.
* @return a LoggingEventBuilder instance, usually <b>this</b>.
*
* @since 2.1.0
*/
default public LoggingEventBuilder kv(String key, char c) {
return addKeyValue(key, (Character) c);
}

/**
* <p>Add a {@link org.slf4j.event.KeyValuePair key value pair} to the event being built, with the value part being
* of type <code>byte</code>.
* </p>
* <p></p>
* <p>The default implementation simply casts to value part to <code>Byte</code> before calling
* {@link #addKeyValue(String, Object)}. However, the
* NOP implementation, i.e {@link NOPLoggingEventBuilder}, skips the cast.</p>
*
* @param key the key of the key value pair.
* @param b the value of type <code>byte</code> of the key value pair.
* @return a LoggingEventBuilder instance, usually <b>this</b>.
*
* @since 2.1.0
*/
default public LoggingEventBuilder kv(String key, byte b) {
return addKeyValue(key, (Byte) b);
}

/**
* <p>Add a {@link org.slf4j.event.KeyValuePair key value pair} to the event being built, with the value part being
* of type <code>short</code>.
* </p>
* <p></p>
* <p>The default implementation simply casts to value part to <code>Short</code> before calling
* {@link #addKeyValue(String, Object)}. However, the
* NOP implementation, i.e {@link NOPLoggingEventBuilder}, skips the cast.</p>
*
* @param key the key of the key value pair.
* @param s the value of type <code>short</code> of the key value pair.
* @return a LoggingEventBuilder instance, usually <b>this</b>.
*
* @since 2.1.0
*/
default public LoggingEventBuilder kv(String key, short s) {
return addKeyValue(key, (Short) s);
}



/**
* <p>Add a {@link org.slf4j.event.KeyValuePair key value pair} to the event being built, with the value part being
* of type <code>int</code>.
* </p>
* <p></p>
* <p>The default implementation simply casts to value part to <code>Integer</code> before calling
* {@link #addKeyValue(String, Object)}. However, the
* NOP implementation, i.e {@link NOPLoggingEventBuilder}, skips the cast.</p>
*
* @param key the key of the key value pair.
* @param i the value of type <code>int</code> of the key value pair.
* @return a LoggingEventBuilder instance, usually <b>this</b>.
*
* @since 2.1.0
*/
default public LoggingEventBuilder kv(String key, int i) {
return addKeyValue(key, (Integer) i);
}

/**
* <p>Add a {@link org.slf4j.event.KeyValuePair key value pair} to the event being built, with the value part being
* of type <code>long</code>.
* </p>
* <p></p>
* <p>The default implementation simply casts to value part to <code>Integer</code> before calling
* {@link #addKeyValue(String, Object)}. However, the
* NOP implementation, i.e {@link NOPLoggingEventBuilder}, skips the cast.</p>
*
* @param key the key of the key value pair.
* @param l the value of type <code>long</code> of the key value pair.
* @return a LoggingEventBuilder instance, usually <b>this</b>.
*
* @since 2.1.0
*/
default public LoggingEventBuilder kv(String key, long l) {
return addKeyValue(key, (Long) l);
}

/**
* <p>Add a {@link org.slf4j.event.KeyValuePair key value pair} to the event being built, with the value part being
* of type <code>float</code>.
* </p>
* <p></p>
* <p>The default implementation simply casts to value part to <code>Float</code> before calling
* {@link #addKeyValue(String, Object)}. However, the
* NOP implementation, i.e {@link NOPLoggingEventBuilder}, skips the cast.</p>
*
* @param key the key of the key value pair.
* @param f the value of type <code>float</code> of the key value pair.
* @return a LoggingEventBuilder instance, usually <b>this</b>.
*
* @since 2.1.0
*/
default public LoggingEventBuilder kv(String key, float f) {
return addKeyValue(key, (Float) f);
}

/**
* <p>Add a {@link org.slf4j.event.KeyValuePair key value pair} to the event being built, with the value part being
* of type <code>double</code>.
* </p>
* <p></p>
* <p>The default implementation simply casts to value part to <code>Double</code> before calling
* {@link #addKeyValue(String, Object)}. However, the
* NOP implementation, i.e {@link NOPLoggingEventBuilder}, skips the cast.</p>
*
* @param key the key of the key value pair.
* @param f the value of type <code>double</code> of the key value pair.
* @return a LoggingEventBuilder instance, usually <b>this</b>.
*
* @since 2.1.0
*/
default public LoggingEventBuilder kv(String key, double f) {
return addKeyValue(key, (Double) f);
}

/**
* Sets the message of the logging event.
*
* @since 2.0.0-beta0
* @param message the message of the event
* @return a LoggingEventBuilder instance, usually <b>this</b>.
* @since 2.0.0
*/
@CheckReturnValue
LoggingEventBuilder setMessage(String message);
Expand All @@ -248,6 +437,7 @@ default LoggingEventBuilder arg(double d) {
* Sets the message of the event via a message supplier.
*
* @param messageSupplier supplies a String to be used as the message for the event
* @return a LoggingEventBuilder instance, usually <b>this</b>.
* @since 2.0.0-beta0
*/
@CheckReturnValue
Expand Down

0 comments on commit f3fedc2

Please sign in to comment.