diff options
Diffstat (limited to 'core/src/main/java/eu/mulk/quarkus/googlecloud/jsonlogging/LabelProvider.java')
-rw-r--r-- | core/src/main/java/eu/mulk/quarkus/googlecloud/jsonlogging/LabelProvider.java | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/core/src/main/java/eu/mulk/quarkus/googlecloud/jsonlogging/LabelProvider.java b/core/src/main/java/eu/mulk/quarkus/googlecloud/jsonlogging/LabelProvider.java new file mode 100644 index 0000000..8cf87db --- /dev/null +++ b/core/src/main/java/eu/mulk/quarkus/googlecloud/jsonlogging/LabelProvider.java @@ -0,0 +1,49 @@ +package eu.mulk.quarkus.googlecloud.jsonlogging; + +import java.util.Collection; + +/** + * A user-supplied provider for {@link Label}s. + * + * <p>Instances of this interface that are registered with the {@link Formatter} are applied to each + * log entry that is logged. + * + * <p>If you are using the Quarkus extension, any CDI beans registered under this interface are + * registered automatically. + * + * <p><strong>Example:</strong> + * + * <pre>{@code + * @Singleton + * @Unremovable + * public final class RequestIdLabelProvider implements LabelProvider { + * + * @Override + * public Collection<Label> getLabels() { + * return List.of(Label.of("requestId", RequestContext.current().getRequestId())); + * } + * } + * }</pre> + * + * Result: + * + * <pre>{@code + * { + * "textPayload": "Request rejected: unauthorized.", + * "labels": { + * "requestId": "123" + * } + * } + * }</pre> + * + * @see StructuredParameterProvider + */ +public interface LabelProvider { + + /** + * Provides a collection of {@link Label}s to add to each log entry that is logged. + * + * @return a collection of {@link Label}s to add to each log entry that is logged. + */ + Collection<Label> getLabels(); +} |