Matthias Andreas Benkard | b8fbc37 | 2021-05-11 06:50:45 +0200 | [diff] [blame] | 1 | package eu.mulk.quarkus.googlecloud.jsonlogging; |
| 2 | |
Matthias Andreas Benkard | 121a631 | 2021-05-12 05:41:25 +0200 | [diff] [blame] | 3 | import java.util.Objects; |
| 4 | |
Matthias Andreas Benkard | 692f48d | 2021-08-31 21:06:50 +0200 | [diff] [blame] | 5 | /** |
| 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 Benkard | 121a631 | 2021-05-12 05:41:25 +0200 | [diff] [blame] | 20 | public 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 Benkard | b8fbc37 | 2021-05-11 06:50:45 +0200 | [diff] [blame] | 29 | |
| 30 | public static Label of(String key, String value) { |
| 31 | return new Label(key, value); |
| 32 | } |
Matthias Andreas Benkard | 121a631 | 2021-05-12 05:41:25 +0200 | [diff] [blame] | 33 | |
| 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 Benkard | b8fbc37 | 2021-05-11 06:50:45 +0200 | [diff] [blame] | 59 | } |