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