diff options
Diffstat (limited to 'runtime/src/main/java/eu/mulk/quarkus/googlecloud/jsonlogging/KeyValueParameter.java')
-rw-r--r-- | runtime/src/main/java/eu/mulk/quarkus/googlecloud/jsonlogging/KeyValueParameter.java | 93 |
1 files changed, 90 insertions, 3 deletions
diff --git a/runtime/src/main/java/eu/mulk/quarkus/googlecloud/jsonlogging/KeyValueParameter.java b/runtime/src/main/java/eu/mulk/quarkus/googlecloud/jsonlogging/KeyValueParameter.java index 173d9e2..a5924b4 100644 --- a/runtime/src/main/java/eu/mulk/quarkus/googlecloud/jsonlogging/KeyValueParameter.java +++ b/runtime/src/main/java/eu/mulk/quarkus/googlecloud/jsonlogging/KeyValueParameter.java @@ -8,18 +8,29 @@ import javax.json.JsonObjectBuilder; import javax.json.JsonValue; /** - * A simple single key--value pair forming a {@link StructuredParameter}. + * A simple single key–value pair forming a {@link StructuredParameter}. * - * <p>This class is suitable for the common case of logging a key—value pair as parameter to the + * <p>This class is suitable for the common case of logging a key–value pair as parameter to the * {@code *f} family of logging functions on {@link org.jboss.logging.Logger}. For advanced use * cases, provide your own implementation of {@link StructuredParameter}. * - * <p>Example: + * <p><strong>Example:</strong> * * <pre>{@code * logger.infof("Application starting.", StructuredParameter.of("version", "1.0")); * }</pre> * + * Result: + * + * <pre>{@code + * { + * "jsonPayload": { + * "message": "Application starting.", + * "version": "1.0" + * } + * } + * }</pre> + * * @see Label * @see StructuredParameter */ @@ -33,30 +44,93 @@ public final class KeyValueParameter implements StructuredParameter { this.value = value; } + /** + * Creates a {@link KeyValueParameter} from a {@link String} value. + * + * <p>The resulting JSON value is of type {@code string}. + * + * @param key the key part of the key–value pair. + * @param value the value part of the key–value pair. + * @return the newly constructed parameter, ready to be passed to a logging function. + */ public static KeyValueParameter of(String key, String value) { return new KeyValueParameter(key, Json.createValue(value)); } + /** + * Creates a {@link KeyValueParameter} from an {@code int} value. + * + * <p>The resulting JSON value is of type {@code number}. + * + * @param key the key part of the key–value pair. + * @param value the value part of the key–value pair. + * @return the newly constructed parameter, ready to be passed to a logging function. + */ public static KeyValueParameter of(String key, int value) { return new KeyValueParameter(key, Json.createValue(value)); } + /** + * Creates a {@link KeyValueParameter} from a {@code long} value. + * + * <p>The resulting JSON value is of type {@code number}. + * + * @param key the key part of the key–value pair. + * @param value the value part of the key–value pair. + * @return the newly constructed parameter, ready to be passed to a logging function. + */ public static KeyValueParameter of(String key, long value) { return new KeyValueParameter(key, Json.createValue(value)); } + /** + * Creates a {@link KeyValueParameter} from a {@code double} value. + * + * <p>The resulting JSON value is of type {@code number}. + * + * @param key the key part of the key–value pair. + * @param value the value part of the key–value pair. + * @return the newly constructed parameter, ready to be passed to a logging function. + */ public static KeyValueParameter of(String key, double value) { return new KeyValueParameter(key, Json.createValue(value)); } + /** + * Creates a {@link KeyValueParameter} from a {@link BigDecimal} value. + * + * <p>The resulting JSON value is of type {@code number}. + * + * @param key the key part of the key–value pair. + * @param value the value part of the key–value pair. + * @return the newly constructed parameter, ready to be passed to a logging function. + */ public static KeyValueParameter of(String key, BigDecimal value) { return new KeyValueParameter(key, Json.createValue(value)); } + /** + * Creates a {@link KeyValueParameter} from a {@link BigInteger} value. + * + * <p>The resulting JSON value is of type {@code number}. + * + * @param key the key part of the key–value pair. + * @param value the value part of the key–value pair. + * @return the newly constructed parameter, ready to be passed to a logging function. + */ public static KeyValueParameter of(String key, BigInteger value) { return new KeyValueParameter(key, Json.createValue(value)); } + /** + * Creates a {@link KeyValueParameter} from a {@code boolean} value. + * + * <p>The resulting JSON value is of type {@code boolean}. + * + * @param key the key part of the key–value pair. + * @param value the value part of the key–value pair. + * @return the newly constructed parameter, ready to be passed to a logging function. + */ public static KeyValueParameter of(String key, boolean value) { return new KeyValueParameter(key, value ? JsonValue.TRUE : JsonValue.FALSE); } @@ -66,10 +140,23 @@ public final class KeyValueParameter implements StructuredParameter { return Json.createObjectBuilder().add(key, value); } + /** + * The key part of the key–value pair. + * + * @return the key part of the key–value pair. + */ public String key() { return key; } + /** + * The value part of the key–value pair. + * + * <p>Can be of any non-composite JSON type (i.e. {@code string}, {@code number}, or {@code + * boolean}). + * + * @return the value pairt of the key–value pair. + */ public JsonValue value() { return value; } |