diff options
Diffstat (limited to 'runtime')
4 files changed, 136 insertions, 21 deletions
| diff --git a/runtime/src/main/java/eu/mulk/quarkus/googlecloud/jsonlogging/Formatter.java b/runtime/src/main/java/eu/mulk/quarkus/googlecloud/jsonlogging/Formatter.java index 0c691b7..d2e5562 100644 --- a/runtime/src/main/java/eu/mulk/quarkus/googlecloud/jsonlogging/Formatter.java +++ b/runtime/src/main/java/eu/mulk/quarkus/googlecloud/jsonlogging/Formatter.java @@ -36,9 +36,10 @@ public class Formatter extends ExtFormatter {      Map<String, String> labels = new HashMap<>();      if (logRecord.getParameters() != null) {        for (var parameter : logRecord.getParameters()) { -        if (parameter instanceof StructuredParameter sparam) { -          parameters.add(sparam); -        } else if (parameter instanceof Label label) { +        if (parameter instanceof StructuredParameter) { +          parameters.add((StructuredParameter) parameter); +        } else if (parameter instanceof Label) { +          var label = (Label) parameter;            labels.put(label.key(), label.value());          }        } diff --git a/runtime/src/main/java/eu/mulk/quarkus/googlecloud/jsonlogging/KeyValueParameter.java b/runtime/src/main/java/eu/mulk/quarkus/googlecloud/jsonlogging/KeyValueParameter.java index 5f582c9..ae2e7e0 100644 --- a/runtime/src/main/java/eu/mulk/quarkus/googlecloud/jsonlogging/KeyValueParameter.java +++ b/runtime/src/main/java/eu/mulk/quarkus/googlecloud/jsonlogging/KeyValueParameter.java @@ -2,11 +2,20 @@ package eu.mulk.quarkus.googlecloud.jsonlogging;  import java.math.BigDecimal;  import java.math.BigInteger; +import java.util.Objects;  import javax.json.Json;  import javax.json.JsonObjectBuilder;  import javax.json.JsonValue; -public record KeyValueParameter(String key, JsonValue value) implements StructuredParameter { +public final class KeyValueParameter implements StructuredParameter { + +  private final String key; +  private final JsonValue value; + +  private KeyValueParameter(String key, JsonValue value) { +    this.key = key; +    this.value = value; +  }    public static KeyValueParameter of(String key, String value) {      return new KeyValueParameter(key, Json.createValue(value)); @@ -40,4 +49,30 @@ public record KeyValueParameter(String key, JsonValue value) implements Structur    public JsonObjectBuilder json() {      return Json.createObjectBuilder().add(key, value);    } + +  public String key() { +    return key; +  } + +  public JsonValue value() { +    return value; +  } + +  @Override +  public boolean equals(Object obj) { +    if (obj == this) return true; +    if (obj == null || obj.getClass() != this.getClass()) return false; +    var that = (KeyValueParameter) obj; +    return Objects.equals(this.key, that.key) && Objects.equals(this.value, that.value); +  } + +  @Override +  public int hashCode() { +    return Objects.hash(key, value); +  } + +  @Override +  public String toString() { +    return "KeyValueParameter[" + "key=" + key + ", " + "value=" + value + ']'; +  }  } diff --git a/runtime/src/main/java/eu/mulk/quarkus/googlecloud/jsonlogging/Label.java b/runtime/src/main/java/eu/mulk/quarkus/googlecloud/jsonlogging/Label.java index 02f7034..7c5d14d 100644 --- a/runtime/src/main/java/eu/mulk/quarkus/googlecloud/jsonlogging/Label.java +++ b/runtime/src/main/java/eu/mulk/quarkus/googlecloud/jsonlogging/Label.java @@ -1,8 +1,44 @@  package eu.mulk.quarkus.googlecloud.jsonlogging; -public record Label(String key, String value) { +import java.util.Objects; + +public final class Label { + +  private final String key; +  private final String value; + +  private Label(String key, String value) { +    this.key = key; +    this.value = value; +  }    public static Label of(String key, String value) {      return new Label(key, value);    } + +  public String key() { +    return key; +  } + +  public String value() { +    return value; +  } + +  @Override +  public boolean equals(Object obj) { +    if (obj == this) return true; +    if (obj == null || obj.getClass() != this.getClass()) return false; +    var that = (Label) obj; +    return Objects.equals(this.key, that.key) && Objects.equals(this.value, that.value); +  } + +  @Override +  public int hashCode() { +    return Objects.hash(key, value); +  } + +  @Override +  public String toString() { +    return "Label[" + "key=" + key + ", " + "value=" + value + ']'; +  }  } diff --git a/runtime/src/main/java/eu/mulk/quarkus/googlecloud/jsonlogging/LogEntry.java b/runtime/src/main/java/eu/mulk/quarkus/googlecloud/jsonlogging/LogEntry.java index 4394033..4c70e6f 100644 --- a/runtime/src/main/java/eu/mulk/quarkus/googlecloud/jsonlogging/LogEntry.java +++ b/runtime/src/main/java/eu/mulk/quarkus/googlecloud/jsonlogging/LogEntry.java @@ -18,21 +18,56 @@ import javax.json.JsonObjectBuilder;   * <p>A few of the fields are treated specially by the fluentd instance running in Google Kubernetes   * Engine. All other fields end up in the jsonPayload field on the Google Cloud Logging side.   */ -record LogEntry( -    String message, -    String severity, -    Timestamp timestamp, -    @Nullable String trace, -    @Nullable String spanId, -    SourceLocation sourceLocation, -    Map<String, String> labels, -    List<StructuredParameter> parameters, -    Map<String, String> mappedDiagnosticContext, -    @Nullable String nestedDiagnosticContext, -    @Nullable String type) { - -  static record SourceLocation( -      @Nullable String file, @Nullable String line, @Nullable String function) { +final class LogEntry { + +  private final String message; +  private final String severity; +  private final Timestamp timestamp; +  @Nullable private final String trace; +  @Nullable private final String spanId; +  private final SourceLocation sourceLocation; +  private final Map<String, String> labels; +  private final List<StructuredParameter> parameters; +  private final Map<String, String> mappedDiagnosticContext; +  @Nullable private final String nestedDiagnosticContext; +  @Nullable private final String type; + +  LogEntry( +      String message, +      String severity, +      Timestamp timestamp, +      @Nullable String trace, +      @Nullable String spanId, +      SourceLocation sourceLocation, +      Map<String, String> labels, +      List<StructuredParameter> parameters, +      Map<String, String> mappedDiagnosticContext, +      @Nullable String nestedDiagnosticContext, +      @Nullable String type) { +    this.message = message; +    this.severity = severity; +    this.timestamp = timestamp; +    this.trace = trace; +    this.spanId = spanId; +    this.sourceLocation = sourceLocation; +    this.labels = labels; +    this.parameters = parameters; +    this.mappedDiagnosticContext = mappedDiagnosticContext; +    this.nestedDiagnosticContext = nestedDiagnosticContext; +    this.type = type; +  } + +  static final class SourceLocation { + +    @Nullable private final String file; +    @Nullable private final String line; +    @Nullable private final String function; + +    SourceLocation(@Nullable String file, @Nullable String line, @Nullable String function) { +      this.file = file; +      this.line = line; +      this.function = function; +    }      JsonObject json() {        return Json.createObjectBuilder() @@ -43,7 +78,15 @@ record LogEntry(      }    } -  static record Timestamp(long seconds, int nanos) { +  static final class Timestamp { + +    private final long seconds; +    private final int nanos; + +    Timestamp(long seconds, int nanos) { +      this.seconds = seconds; +      this.nanos = nanos; +    }      Timestamp(Instant t) {        this(t.getEpochSecond(), t.getNano()); | 
