summaryrefslogtreecommitdiff
path: root/runtime/src/main/java/eu/mulk/quarkus/googlecloud/jsonlogging/GoogleCloudJsonLoggingRecorder.java
blob: 7234a71f1ab1a23510687ee23b6ea2ed98e0fee8 (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
package eu.mulk.quarkus.googlecloud.jsonlogging;

import io.quarkus.arc.Arc;
import io.quarkus.runtime.RuntimeValue;
import io.quarkus.runtime.annotations.Recorder;
import java.util.Collection;
import java.util.Optional;
import java.util.stream.Collectors;

/** A Quarkus recorder that registers {@link Formatter} as a log formatter for the application. */
@Recorder
public class GoogleCloudJsonLoggingRecorder {

  /**
   * Registers {@link Formatter} as a log formatter for the application.
   *
   * <p>Collects all discoverable {@link StructuredParameterProvider}s and {@link LabelProvider}s
   * and passes them to {@link Formatter#Formatter(Collection, Collection)}.
   *
   * @return the registered {@link Formatter}.
   */
  public RuntimeValue<Optional<java.util.logging.Formatter>> initialize() {

    var parameterProviders =
        Arc.container().select(StructuredParameterProvider.class).stream()
            .collect(Collectors.toList());

    var labelProviders =
        Arc.container().select(LabelProvider.class).stream().collect(Collectors.toList());

    return new RuntimeValue<>(Optional.of(new Formatter(parameterProviders, labelProviders)));
  }
}