blob: 72929f18be6e4e00ab14e8630ff4d1a1f0834380 [file] [log] [blame]
Matthias Andreas Benkardb8fbc372021-05-11 06:50:45 +02001package eu.mulk.quarkus.googlecloud.jsonlogging;
2
Matthias Andreas Benkard121a6312021-05-12 05:41:25 +02003import java.util.Objects;
4
Matthias Andreas Benkard692f48d2021-08-31 21:06:50 +02005/**
6 * A label usable to tag a log message.
7 *
8 * <p>Instances of {@link Label} can be passed as log parameters to the {@code *f} family of logging
9 * functions on {@link org.jboss.logging.Logger}.
10 *
11 * <p>Example:
12 *
13 * <pre>{@code
14 * logger.logf("Request rejected: unauthorized.", Label.of("requestId", "123"));
15 * }</pre>
16 *
17 * @see KeyValueParameter
18 * @see StructuredParameter
19 */
Matthias Andreas Benkard121a6312021-05-12 05:41:25 +020020public final class Label {
21
22 private final String key;
23 private final String value;
24
25 private Label(String key, String value) {
26 this.key = key;
27 this.value = value;
28 }
Matthias Andreas Benkardb8fbc372021-05-11 06:50:45 +020029
30 public static Label of(String key, String value) {
31 return new Label(key, value);
32 }
Matthias Andreas Benkard121a6312021-05-12 05:41:25 +020033
34 public String key() {
35 return key;
36 }
37
38 public String value() {
39 return value;
40 }
41
42 @Override
43 public boolean equals(Object obj) {
44 if (obj == this) return true;
45 if (obj == null || obj.getClass() != this.getClass()) return false;
46 var that = (Label) obj;
47 return Objects.equals(this.key, that.key) && Objects.equals(this.value, that.value);
48 }
49
50 @Override
51 public int hashCode() {
52 return Objects.hash(key, value);
53 }
54
55 @Override
56 public String toString() {
57 return "Label[" + "key=" + key + ", " + "value=" + value + ']';
58 }
Matthias Andreas Benkardb8fbc372021-05-11 06:50:45 +020059}