blob: 70bdce6b4ef9df1eafc37810643934dbf47f1aff (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
// SPDX-FileCopyrightText: © 2021 Matthias Andreas Benkard <code@mail.matthias.benkard.de>
//
// SPDX-License-Identifier: LGPL-3.0-or-later
package eu.mulk.quarkus.googlecloud.jsonlogging;
/**
* A user-supplied provider for {@link StructuredParameter}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 TraceLogParameterProvider implements StructuredParameterProvider {
*
* @Override
* public StructuredParameter getParameter() {
* var b = Json.createObjectBuilder();
* b.add("traceId", Span.current().getSpanContext().getTraceId());
* b.add("spanId", Span.current().getSpanContext().getSpanId());
* return () -> b;
* }
* }
* }</pre>
*
* Result:
*
* <pre>{@code
* {
* "jsonPayload": {
* "message": "Request rejected: unauthorized.",
* "traceId": "39f9a49a9567a8bd7087b708f8932550",
* "spanId": "c7431b14630b633d"
* }
* }
* }</pre>
*
* @see LabelProvider
*/
public interface StructuredParameterProvider {
/**
* Provides a {@link StructuredParameter} to add to each log entry that is logged.
*
* <p>It is often useful to return a custom {@link StructuredParameter} rather than a {@link
* KeyValueParameter} from this method. This way multiple key–value pairs can be generated by a
* single invocation.
*
* @return a {@link StructuredParameter} to add to each log entry that is logged.
*/
StructuredParameter getParameter();
}
|