Matthias Andreas Benkard | 692f48d | 2021-08-31 21:06:50 +0200 | [diff] [blame] | 1 | package eu.mulk.quarkus.googlecloud.jsonlogging; |
| 2 | |
| 3 | import java.util.Collection; |
| 4 | |
| 5 | /** |
| 6 | * A user-supplied provider for {@link Label}s. |
| 7 | * |
| 8 | * <p>Any CDI beans registered under this class are applied to each log entry that is logged. |
| 9 | * |
Matthias Andreas Benkard | 42da9f1 | 2021-09-02 18:47:28 +0200 | [diff] [blame^] | 10 | * <p><strong>Example:</strong> |
| 11 | * |
| 12 | * <pre>{@code |
| 13 | * @Singleton |
| 14 | * @Unremovable |
| 15 | * public final class RequestIdLabelProvider implements LabelProvider { |
| 16 | * |
| 17 | * @Override |
| 18 | * public Collection<Label> getLabels() { |
| 19 | * return List.of(Label.of("requestId", RequestContext.current().getRequestId())); |
| 20 | * } |
| 21 | * } |
| 22 | * }</pre> |
| 23 | * |
| 24 | * Result: |
| 25 | * |
| 26 | * <pre>{@code |
| 27 | * { |
| 28 | * "textPayload": "Request rejected: unauthorized.", |
| 29 | * "labels": { |
| 30 | * "requestId": "123" |
| 31 | * } |
| 32 | * } |
| 33 | * }</pre> |
| 34 | * |
Matthias Andreas Benkard | 692f48d | 2021-08-31 21:06:50 +0200 | [diff] [blame] | 35 | * @see StructuredParameterProvider |
| 36 | */ |
| 37 | public interface LabelProvider { |
| 38 | |
Matthias Andreas Benkard | 42da9f1 | 2021-09-02 18:47:28 +0200 | [diff] [blame^] | 39 | /** |
| 40 | * Provides a collection of {@link Label}s to add to each log entry that is logged. |
| 41 | * |
| 42 | * @return a collection of {@link Label}s to add to each log entry that is logged. |
| 43 | */ |
Matthias Andreas Benkard | 692f48d | 2021-08-31 21:06:50 +0200 | [diff] [blame] | 44 | Collection<Label> getLabels(); |
| 45 | } |