blob: 0588fbb272e7177f99f4332d93672e9d689d8edb [file] [log] [blame]
Matthias Andreas Benkard80909242022-02-03 20:47:47 +01001// SPDX-FileCopyrightText: © 2021 Matthias Andreas Benkard <code@mail.matthias.benkard.de>
2//
3// SPDX-License-Identifier: LGPL-3.0-or-later
4
Matthias Andreas Benkard692f48d2021-08-31 21:06:50 +02005package eu.mulk.quarkus.googlecloud.jsonlogging;
6
7import java.util.Collection;
8
9/**
10 * A user-supplied provider for {@link Label}s.
11 *
Matthias Andreas Benkard20210242022-01-15 10:39:30 +010012 * <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 Benkard692f48d2021-08-31 21:06:50 +020017 *
Matthias Andreas Benkard42da9f12021-09-02 18:47:28 +020018 * <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 Benkard692f48d2021-08-31 21:06:50 +020043 * @see StructuredParameterProvider
44 */
45public interface LabelProvider {
46
Matthias Andreas Benkard42da9f12021-09-02 18:47:28 +020047 /**
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 Benkard692f48d2021-08-31 21:06:50 +020052 Collection<Label> getLabels();
53}