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 | * |
Matthias Andreas Benkard | 2021024 | 2022-01-15 10:39:30 +0100 | [diff] [blame^] | 8 | * <p>Instances of this interface that are registered with the {@link Formatter} are applied to each |
| 9 | * log entry that is logged. |
| 10 | * |
| 11 | * <p>If you are using the Quarkus extension, any CDI beans registered under this interface are |
| 12 | * registered automatically. |
Matthias Andreas Benkard | 692f48d | 2021-08-31 21:06:50 +0200 | [diff] [blame] | 13 | * |
Matthias Andreas Benkard | 42da9f1 | 2021-09-02 18:47:28 +0200 | [diff] [blame] | 14 | * <p><strong>Example:</strong> |
| 15 | * |
| 16 | * <pre>{@code |
| 17 | * @Singleton |
| 18 | * @Unremovable |
| 19 | * public final class RequestIdLabelProvider implements LabelProvider { |
| 20 | * |
| 21 | * @Override |
| 22 | * public Collection<Label> getLabels() { |
| 23 | * return List.of(Label.of("requestId", RequestContext.current().getRequestId())); |
| 24 | * } |
| 25 | * } |
| 26 | * }</pre> |
| 27 | * |
| 28 | * Result: |
| 29 | * |
| 30 | * <pre>{@code |
| 31 | * { |
| 32 | * "textPayload": "Request rejected: unauthorized.", |
| 33 | * "labels": { |
| 34 | * "requestId": "123" |
| 35 | * } |
| 36 | * } |
| 37 | * }</pre> |
| 38 | * |
Matthias Andreas Benkard | 692f48d | 2021-08-31 21:06:50 +0200 | [diff] [blame] | 39 | * @see StructuredParameterProvider |
| 40 | */ |
| 41 | public interface LabelProvider { |
| 42 | |
Matthias Andreas Benkard | 42da9f1 | 2021-09-02 18:47:28 +0200 | [diff] [blame] | 43 | /** |
| 44 | * Provides a collection of {@link Label}s to add to each log entry that is logged. |
| 45 | * |
| 46 | * @return a collection of {@link Label}s to add to each log entry that is logged. |
| 47 | */ |
Matthias Andreas Benkard | 692f48d | 2021-08-31 21:06:50 +0200 | [diff] [blame] | 48 | Collection<Label> getLabels(); |
| 49 | } |