From 95a25f4377e6b7b0e68fff22c5bf460c1ccab359 Mon Sep 17 00:00:00 2001 From: Maciej Walkowiak Date: Tue, 9 Mar 2021 10:38:40 +0100 Subject: [PATCH] Fix: Use logger set on SentryOptions in GsonSerializer Fixes #1308 --- .../main/kotlin/io/sentry/test/assertions.kt | 3 +- sentry/api/sentry.api | 36 ++++++------- .../main/java/io/sentry/GsonSerializer.java | 54 ++++++++++--------- .../main/java/io/sentry/SentryOptions.java | 2 +- .../main/java/io/sentry/SessionAdapter.java | 16 +++--- .../adapters/ContextsDeserializerAdapter.java | 14 ++--- .../adapters/ContextsSerializerAdapter.java | 10 ++-- .../adapters/DateDeserializerAdapter.java | 22 ++++---- .../adapters/DateSerializerAdapter.java | 10 ++-- .../OrientationDeserializerAdapter.java | 10 ++-- .../OrientationSerializerAdapter.java | 10 ++-- .../adapters/SentryIdDeserializerAdapter.java | 10 ++-- .../adapters/SentryIdSerializerAdapter.java | 10 ++-- .../SentryLevelDeserializerAdapter.java | 10 ++-- .../SentryLevelSerializerAdapter.java | 10 ++-- .../adapters/SpanIdDeserializerAdapter.java | 10 ++-- .../adapters/SpanIdSerializerAdapter.java | 10 ++-- .../SpanStatusDeserializerAdapter.java | 10 ++-- .../adapters/SpanStatusSerializerAdapter.java | 10 ++-- .../adapters/TimeZoneDeserializerAdapter.java | 10 ++-- .../adapters/TimeZoneSerializerAdapter.java | 10 ++-- .../test/java/io/sentry/GsonSerializerTest.kt | 24 ++++++++- .../test/java/io/sentry/SentryClientTest.kt | 2 +- .../test/java/io/sentry/SessionAdapterTest.kt | 2 +- .../java/io/sentry/cache/CacheStrategyTest.kt | 4 +- 25 files changed, 175 insertions(+), 144 deletions(-) diff --git a/sentry-test-support/src/main/kotlin/io/sentry/test/assertions.kt b/sentry-test-support/src/main/kotlin/io/sentry/test/assertions.kt index 4b8ca59710..b212a71041 100644 --- a/sentry-test-support/src/main/kotlin/io/sentry/test/assertions.kt +++ b/sentry-test-support/src/main/kotlin/io/sentry/test/assertions.kt @@ -2,7 +2,6 @@ package io.sentry.test import com.nhaarman.mockitokotlin2.check import io.sentry.GsonSerializer -import io.sentry.NoOpLogger import io.sentry.SentryEnvelope import io.sentry.SentryEvent import io.sentry.SentryOptions @@ -12,7 +11,7 @@ import io.sentry.SentryOptions */ inline fun checkEvent(noinline predicate: (SentryEvent) -> Unit): SentryEnvelope { val options = SentryOptions().apply { - setSerializer(GsonSerializer(NoOpLogger.getInstance(), envelopeReader)) + setSerializer(GsonSerializer(SentryOptions(), envelopeReader)) } return check { val event = it.items.first().getEvent(options.serializer)!! diff --git a/sentry/api/sentry.api b/sentry/api/sentry.api index f5655e892c..8e9c385484 100644 --- a/sentry/api/sentry.api +++ b/sentry/api/sentry.api @@ -90,7 +90,7 @@ public abstract interface class io/sentry/EventProcessor { } public final class io/sentry/GsonSerializer : io/sentry/ISerializer { - public fun (Lio/sentry/ILogger;Lio/sentry/IEnvelopeReader;)V + public fun (Lio/sentry/SentryOptions;Lio/sentry/IEnvelopeReader;)V public fun deserialize (Ljava/io/Reader;Ljava/lang/Class;)Ljava/lang/Object; public fun deserializeEnvelope (Ljava/io/InputStream;)Lio/sentry/SentryEnvelope; public fun serialize (Lio/sentry/SentryEnvelope;Ljava/io/OutputStream;)V @@ -906,7 +906,7 @@ public final class io/sentry/Session$State : java/lang/Enum { } public final class io/sentry/SessionAdapter : com/google/gson/TypeAdapter { - public fun (Lio/sentry/ILogger;)V + public fun (Lio/sentry/SentryOptions;)V public fun read (Lcom/google/gson/stream/JsonReader;)Lio/sentry/Session; public synthetic fun read (Lcom/google/gson/stream/JsonReader;)Ljava/lang/Object; public fun write (Lcom/google/gson/stream/JsonWriter;Lio/sentry/Session;)V @@ -1036,25 +1036,25 @@ public final class io/sentry/adapters/CollectionAdapter : com/google/gson/JsonSe } public final class io/sentry/adapters/ContextsDeserializerAdapter : com/google/gson/JsonDeserializer { - public fun (Lio/sentry/ILogger;)V + public fun (Lio/sentry/SentryOptions;)V public fun deserialize (Lcom/google/gson/JsonElement;Ljava/lang/reflect/Type;Lcom/google/gson/JsonDeserializationContext;)Lio/sentry/protocol/Contexts; public synthetic fun deserialize (Lcom/google/gson/JsonElement;Ljava/lang/reflect/Type;Lcom/google/gson/JsonDeserializationContext;)Ljava/lang/Object; } public final class io/sentry/adapters/ContextsSerializerAdapter : com/google/gson/JsonSerializer { - public fun (Lio/sentry/ILogger;)V + public fun (Lio/sentry/SentryOptions;)V public fun serialize (Lio/sentry/protocol/Contexts;Ljava/lang/reflect/Type;Lcom/google/gson/JsonSerializationContext;)Lcom/google/gson/JsonElement; public synthetic fun serialize (Ljava/lang/Object;Ljava/lang/reflect/Type;Lcom/google/gson/JsonSerializationContext;)Lcom/google/gson/JsonElement; } public final class io/sentry/adapters/DateDeserializerAdapter : com/google/gson/JsonDeserializer { - public fun (Lio/sentry/ILogger;)V + public fun (Lio/sentry/SentryOptions;)V public synthetic fun deserialize (Lcom/google/gson/JsonElement;Ljava/lang/reflect/Type;Lcom/google/gson/JsonDeserializationContext;)Ljava/lang/Object; public fun deserialize (Lcom/google/gson/JsonElement;Ljava/lang/reflect/Type;Lcom/google/gson/JsonDeserializationContext;)Ljava/util/Date; } public final class io/sentry/adapters/DateSerializerAdapter : com/google/gson/JsonSerializer { - public fun (Lio/sentry/ILogger;)V + public fun (Lio/sentry/SentryOptions;)V public synthetic fun serialize (Ljava/lang/Object;Ljava/lang/reflect/Type;Lcom/google/gson/JsonSerializationContext;)Lcom/google/gson/JsonElement; public fun serialize (Ljava/util/Date;Ljava/lang/reflect/Type;Lcom/google/gson/JsonSerializationContext;)Lcom/google/gson/JsonElement; } @@ -1066,73 +1066,73 @@ public final class io/sentry/adapters/MapAdapter : com/google/gson/JsonSerialize } public final class io/sentry/adapters/OrientationDeserializerAdapter : com/google/gson/JsonDeserializer { - public fun (Lio/sentry/ILogger;)V + public fun (Lio/sentry/SentryOptions;)V public fun deserialize (Lcom/google/gson/JsonElement;Ljava/lang/reflect/Type;Lcom/google/gson/JsonDeserializationContext;)Lio/sentry/protocol/Device$DeviceOrientation; public synthetic fun deserialize (Lcom/google/gson/JsonElement;Ljava/lang/reflect/Type;Lcom/google/gson/JsonDeserializationContext;)Ljava/lang/Object; } public final class io/sentry/adapters/OrientationSerializerAdapter : com/google/gson/JsonSerializer { - public fun (Lio/sentry/ILogger;)V + public fun (Lio/sentry/SentryOptions;)V public fun serialize (Lio/sentry/protocol/Device$DeviceOrientation;Ljava/lang/reflect/Type;Lcom/google/gson/JsonSerializationContext;)Lcom/google/gson/JsonElement; public synthetic fun serialize (Ljava/lang/Object;Ljava/lang/reflect/Type;Lcom/google/gson/JsonSerializationContext;)Lcom/google/gson/JsonElement; } public final class io/sentry/adapters/SentryIdDeserializerAdapter : com/google/gson/JsonDeserializer { - public fun (Lio/sentry/ILogger;)V + public fun (Lio/sentry/SentryOptions;)V public fun deserialize (Lcom/google/gson/JsonElement;Ljava/lang/reflect/Type;Lcom/google/gson/JsonDeserializationContext;)Lio/sentry/protocol/SentryId; public synthetic fun deserialize (Lcom/google/gson/JsonElement;Ljava/lang/reflect/Type;Lcom/google/gson/JsonDeserializationContext;)Ljava/lang/Object; } public final class io/sentry/adapters/SentryIdSerializerAdapter : com/google/gson/JsonSerializer { - public fun (Lio/sentry/ILogger;)V + public fun (Lio/sentry/SentryOptions;)V public fun serialize (Lio/sentry/protocol/SentryId;Ljava/lang/reflect/Type;Lcom/google/gson/JsonSerializationContext;)Lcom/google/gson/JsonElement; public synthetic fun serialize (Ljava/lang/Object;Ljava/lang/reflect/Type;Lcom/google/gson/JsonSerializationContext;)Lcom/google/gson/JsonElement; } public final class io/sentry/adapters/SentryLevelDeserializerAdapter : com/google/gson/JsonDeserializer { - public fun (Lio/sentry/ILogger;)V + public fun (Lio/sentry/SentryOptions;)V public fun deserialize (Lcom/google/gson/JsonElement;Ljava/lang/reflect/Type;Lcom/google/gson/JsonDeserializationContext;)Lio/sentry/SentryLevel; public synthetic fun deserialize (Lcom/google/gson/JsonElement;Ljava/lang/reflect/Type;Lcom/google/gson/JsonDeserializationContext;)Ljava/lang/Object; } public final class io/sentry/adapters/SentryLevelSerializerAdapter : com/google/gson/JsonSerializer { - public fun (Lio/sentry/ILogger;)V + public fun (Lio/sentry/SentryOptions;)V public fun serialize (Lio/sentry/SentryLevel;Ljava/lang/reflect/Type;Lcom/google/gson/JsonSerializationContext;)Lcom/google/gson/JsonElement; public synthetic fun serialize (Ljava/lang/Object;Ljava/lang/reflect/Type;Lcom/google/gson/JsonSerializationContext;)Lcom/google/gson/JsonElement; } public final class io/sentry/adapters/SpanIdDeserializerAdapter : com/google/gson/JsonDeserializer { - public fun (Lio/sentry/ILogger;)V + public fun (Lio/sentry/SentryOptions;)V public fun deserialize (Lcom/google/gson/JsonElement;Ljava/lang/reflect/Type;Lcom/google/gson/JsonDeserializationContext;)Lio/sentry/SpanId; public synthetic fun deserialize (Lcom/google/gson/JsonElement;Ljava/lang/reflect/Type;Lcom/google/gson/JsonDeserializationContext;)Ljava/lang/Object; } public final class io/sentry/adapters/SpanIdSerializerAdapter : com/google/gson/JsonSerializer { - public fun (Lio/sentry/ILogger;)V + public fun (Lio/sentry/SentryOptions;)V public fun serialize (Lio/sentry/SpanId;Ljava/lang/reflect/Type;Lcom/google/gson/JsonSerializationContext;)Lcom/google/gson/JsonElement; public synthetic fun serialize (Ljava/lang/Object;Ljava/lang/reflect/Type;Lcom/google/gson/JsonSerializationContext;)Lcom/google/gson/JsonElement; } public final class io/sentry/adapters/SpanStatusDeserializerAdapter : com/google/gson/JsonDeserializer { - public fun (Lio/sentry/ILogger;)V + public fun (Lio/sentry/SentryOptions;)V public fun deserialize (Lcom/google/gson/JsonElement;Ljava/lang/reflect/Type;Lcom/google/gson/JsonDeserializationContext;)Lio/sentry/SpanStatus; public synthetic fun deserialize (Lcom/google/gson/JsonElement;Ljava/lang/reflect/Type;Lcom/google/gson/JsonDeserializationContext;)Ljava/lang/Object; } public final class io/sentry/adapters/SpanStatusSerializerAdapter : com/google/gson/JsonSerializer { - public fun (Lio/sentry/ILogger;)V + public fun (Lio/sentry/SentryOptions;)V public fun serialize (Lio/sentry/SpanStatus;Ljava/lang/reflect/Type;Lcom/google/gson/JsonSerializationContext;)Lcom/google/gson/JsonElement; public synthetic fun serialize (Ljava/lang/Object;Ljava/lang/reflect/Type;Lcom/google/gson/JsonSerializationContext;)Lcom/google/gson/JsonElement; } public final class io/sentry/adapters/TimeZoneDeserializerAdapter : com/google/gson/JsonDeserializer { - public fun (Lio/sentry/ILogger;)V + public fun (Lio/sentry/SentryOptions;)V public synthetic fun deserialize (Lcom/google/gson/JsonElement;Ljava/lang/reflect/Type;Lcom/google/gson/JsonDeserializationContext;)Ljava/lang/Object; public fun deserialize (Lcom/google/gson/JsonElement;Ljava/lang/reflect/Type;Lcom/google/gson/JsonDeserializationContext;)Ljava/util/TimeZone; } public final class io/sentry/adapters/TimeZoneSerializerAdapter : com/google/gson/JsonSerializer { - public fun (Lio/sentry/ILogger;)V + public fun (Lio/sentry/SentryOptions;)V public synthetic fun serialize (Ljava/lang/Object;Ljava/lang/reflect/Type;Lcom/google/gson/JsonSerializationContext;)Lcom/google/gson/JsonElement; public fun serialize (Ljava/util/TimeZone;Ljava/lang/reflect/Type;Lcom/google/gson/JsonSerializationContext;)Lcom/google/gson/JsonElement; } diff --git a/sentry/src/main/java/io/sentry/GsonSerializer.java b/sentry/src/main/java/io/sentry/GsonSerializer.java index 401e96db61..ae9b60e72a 100644 --- a/sentry/src/main/java/io/sentry/GsonSerializer.java +++ b/sentry/src/main/java/io/sentry/GsonSerializer.java @@ -48,8 +48,8 @@ public final class GsonSerializer implements ISerializer { @SuppressWarnings("CharsetObjectCanBeUsed") private static final Charset UTF_8 = Charset.forName("UTF-8"); - /** the ILogger interface */ - private final @NotNull ILogger logger; + /** the SentryOptions */ + private final @NotNull SentryOptions options; /** the Gson instance */ private final @NotNull Gson gson; @@ -60,12 +60,12 @@ public final class GsonSerializer implements ISerializer { /** * AndroidSerializer ctor * - * @param logger the ILogger interface + * @param options the SentryOptions object * @param envelopeReader the IEnvelopeReader interface */ public GsonSerializer( - final @NotNull ILogger logger, final @NotNull IEnvelopeReader envelopeReader) { - this.logger = Objects.requireNonNull(logger, "The ILogger object is required."); + final @NotNull SentryOptions options, final @NotNull IEnvelopeReader envelopeReader) { + this.options = Objects.requireNonNull(options, "The SentryOptions object is required."); this.envelopeReader = Objects.requireNonNull(envelopeReader, "The IEnvelopeReader object is required."); @@ -80,28 +80,28 @@ public GsonSerializer( private @NotNull Gson provideGson() { return new GsonBuilder() .setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES) - .registerTypeAdapter(SentryId.class, new SentryIdSerializerAdapter(logger)) - .registerTypeAdapter(SentryId.class, new SentryIdDeserializerAdapter(logger)) - .registerTypeAdapter(Date.class, new DateSerializerAdapter(logger)) - .registerTypeAdapter(Date.class, new DateDeserializerAdapter(logger)) - .registerTypeAdapter(TimeZone.class, new TimeZoneSerializerAdapter(logger)) - .registerTypeAdapter(TimeZone.class, new TimeZoneDeserializerAdapter(logger)) + .registerTypeAdapter(SentryId.class, new SentryIdSerializerAdapter(options)) + .registerTypeAdapter(SentryId.class, new SentryIdDeserializerAdapter(options)) + .registerTypeAdapter(Date.class, new DateSerializerAdapter(options)) + .registerTypeAdapter(Date.class, new DateDeserializerAdapter(options)) + .registerTypeAdapter(TimeZone.class, new TimeZoneSerializerAdapter(options)) + .registerTypeAdapter(TimeZone.class, new TimeZoneDeserializerAdapter(options)) .registerTypeAdapter( - Device.DeviceOrientation.class, new OrientationSerializerAdapter(logger)) + Device.DeviceOrientation.class, new OrientationSerializerAdapter(options)) .registerTypeAdapter( - Device.DeviceOrientation.class, new OrientationDeserializerAdapter(logger)) - .registerTypeAdapter(SentryLevel.class, new SentryLevelSerializerAdapter(logger)) - .registerTypeAdapter(SentryLevel.class, new SentryLevelDeserializerAdapter(logger)) - .registerTypeAdapter(Contexts.class, new ContextsDeserializerAdapter(logger)) - .registerTypeAdapter(Contexts.class, new ContextsSerializerAdapter(logger)) + Device.DeviceOrientation.class, new OrientationDeserializerAdapter(options)) + .registerTypeAdapter(SentryLevel.class, new SentryLevelSerializerAdapter(options)) + .registerTypeAdapter(SentryLevel.class, new SentryLevelDeserializerAdapter(options)) + .registerTypeAdapter(Contexts.class, new ContextsDeserializerAdapter(options)) + .registerTypeAdapter(Contexts.class, new ContextsSerializerAdapter(options)) .registerTypeAdapterFactory(UnknownPropertiesTypeAdapterFactory.get()) .registerTypeAdapter(SentryEnvelopeHeader.class, new SentryEnvelopeHeaderAdapter()) .registerTypeAdapter(SentryEnvelopeItemHeader.class, new SentryEnvelopeItemHeaderAdapter()) - .registerTypeAdapter(Session.class, new SessionAdapter(logger)) - .registerTypeAdapter(SpanId.class, new SpanIdDeserializerAdapter(logger)) - .registerTypeAdapter(SpanId.class, new SpanIdSerializerAdapter(logger)) - .registerTypeAdapter(SpanStatus.class, new SpanStatusDeserializerAdapter(logger)) - .registerTypeAdapter(SpanStatus.class, new SpanStatusSerializerAdapter(logger)) + .registerTypeAdapter(Session.class, new SessionAdapter(options)) + .registerTypeAdapter(SpanId.class, new SpanIdDeserializerAdapter(options)) + .registerTypeAdapter(SpanId.class, new SpanIdSerializerAdapter(options)) + .registerTypeAdapter(SpanStatus.class, new SpanStatusDeserializerAdapter(options)) + .registerTypeAdapter(SpanStatus.class, new SpanStatusSerializerAdapter(options)) .registerTypeHierarchyAdapter(Collection.class, new CollectionAdapter()) .registerTypeHierarchyAdapter(Map.class, new MapAdapter()) .disableHtmlEscaping() @@ -135,7 +135,7 @@ Device.DeviceOrientation.class, new OrientationDeserializerAdapter(logger)) try { return envelopeReader.read(inputStream); } catch (IOException e) { - logger.log(SentryLevel.ERROR, "Error deserializing envelope.", e); + options.getLogger().log(SentryLevel.ERROR, "Error deserializing envelope.", e); return null; } } @@ -146,8 +146,8 @@ public void serialize(final @NotNull T entity, final @NotNull Writer writer) Objects.requireNonNull(entity, "The entity is required."); Objects.requireNonNull(writer, "The Writer object is required."); - if (logger.isEnabled(SentryLevel.DEBUG)) { - logger.log(SentryLevel.DEBUG, "Serializing object: %s", gson.toJson(entity)); + if (options.getLogger().isEnabled(SentryLevel.DEBUG)) { + options.getLogger().log(SentryLevel.DEBUG, "Serializing object: %s", gson.toJson(entity)); } gson.toJson(entity, entity.getClass(), writer); @@ -187,7 +187,9 @@ public void serialize( writer.write("\n"); } catch (Exception exception) { - logger.log(SentryLevel.ERROR, "Failed to create envelope item. Dropping it.", exception); + options + .getLogger() + .log(SentryLevel.ERROR, "Failed to create envelope item. Dropping it.", exception); } } writer.flush(); diff --git a/sentry/src/main/java/io/sentry/SentryOptions.java b/sentry/src/main/java/io/sentry/SentryOptions.java index ab4c280e57..ebfad264f5 100644 --- a/sentry/src/main/java/io/sentry/SentryOptions.java +++ b/sentry/src/main/java/io/sentry/SentryOptions.java @@ -81,7 +81,7 @@ public class SentryOptions { private @NotNull IEnvelopeReader envelopeReader = new EnvelopeReader(); /** Serializer interface to serialize/deserialize json events */ - private @NotNull ISerializer serializer = new GsonSerializer(logger, envelopeReader); + private @NotNull ISerializer serializer = new GsonSerializer(this, envelopeReader); /** * Sentry client name used for the HTTP authHeader and userAgent eg diff --git a/sentry/src/main/java/io/sentry/SessionAdapter.java b/sentry/src/main/java/io/sentry/SessionAdapter.java index cfee92a73e..d050c133fd 100644 --- a/sentry/src/main/java/io/sentry/SessionAdapter.java +++ b/sentry/src/main/java/io/sentry/SessionAdapter.java @@ -17,10 +17,10 @@ @ApiStatus.Internal public final class SessionAdapter extends TypeAdapter { - private final @NotNull ILogger logger; + private final @NotNull SentryOptions options; - public SessionAdapter(final @NotNull ILogger logger) { - this.logger = Objects.requireNonNull(logger, "The Logger is required."); + public SessionAdapter(final @NotNull SentryOptions options) { + this.options = Objects.requireNonNull(options, "The SentryOptions is required."); } @Override @@ -137,7 +137,7 @@ public Session read(JsonReader reader) throws IOException { sidStr = reader.nextString(); sid = UUID.fromString(sidStr); } catch (IllegalArgumentException e) { - logger.log(SentryLevel.ERROR, "%s sid is not valid.", sidStr); + options.getLogger().log(SentryLevel.ERROR, "%s sid is not valid.", sidStr); } break; case "did": @@ -155,7 +155,7 @@ public Session read(JsonReader reader) throws IOException { statusStr = StringUtils.capitalize(reader.nextString()); status = Session.State.valueOf(statusStr); } catch (IllegalArgumentException e) { - logger.log(SentryLevel.ERROR, "%s status is not valid.", statusStr); + options.getLogger().log(SentryLevel.ERROR, "%s status is not valid.", statusStr); } break; case "errors": @@ -204,7 +204,9 @@ public Session read(JsonReader reader) throws IOException { reader.endObject(); if (status == null || started == null || release == null || release.isEmpty()) { - logger.log(SentryLevel.ERROR, "Session is gonna be dropped due to invalid fields."); + options + .getLogger() + .log(SentryLevel.ERROR, "Session is gonna be dropped due to invalid fields."); return null; } @@ -229,7 +231,7 @@ public Session read(JsonReader reader) throws IOException { try { return DateUtils.getDateTime(timestamp); } catch (IllegalArgumentException e) { - logger.log(SentryLevel.ERROR, e, "Error converting session (%s) field.", field); + options.getLogger().log(SentryLevel.ERROR, e, "Error converting session (%s) field.", field); } return null; } diff --git a/sentry/src/main/java/io/sentry/adapters/ContextsDeserializerAdapter.java b/sentry/src/main/java/io/sentry/adapters/ContextsDeserializerAdapter.java index 6510650de3..99542cc506 100644 --- a/sentry/src/main/java/io/sentry/adapters/ContextsDeserializerAdapter.java +++ b/sentry/src/main/java/io/sentry/adapters/ContextsDeserializerAdapter.java @@ -5,8 +5,8 @@ import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.JsonParseException; -import io.sentry.ILogger; import io.sentry.SentryLevel; +import io.sentry.SentryOptions; import io.sentry.SpanContext; import io.sentry.protocol.App; import io.sentry.protocol.Browser; @@ -23,10 +23,10 @@ @ApiStatus.Internal public final class ContextsDeserializerAdapter implements JsonDeserializer { - private final @NotNull ILogger logger; + private final @NotNull SentryOptions options; - public ContextsDeserializerAdapter(@NotNull final ILogger logger) { - this.logger = logger; + public ContextsDeserializerAdapter(final @NotNull SentryOptions options) { + this.options = options; } @Override @@ -89,7 +89,9 @@ public Contexts deserialize(JsonElement json, Type typeOfT, JsonDeserializationC final Object object = context.deserialize(element, Object.class); contexts.put(key, object); } catch (JsonParseException e) { - logger.log(SentryLevel.ERROR, e, "Error when deserializing the %s key.", key); + options + .getLogger() + .log(SentryLevel.ERROR, e, "Error when deserializing the %s key.", key); } } break; @@ -99,7 +101,7 @@ public Contexts deserialize(JsonElement json, Type typeOfT, JsonDeserializationC return contexts; } } catch (Exception e) { - logger.log(SentryLevel.ERROR, "Error when deserializing Contexts", e); + options.getLogger().log(SentryLevel.ERROR, "Error when deserializing Contexts", e); } return null; } diff --git a/sentry/src/main/java/io/sentry/adapters/ContextsSerializerAdapter.java b/sentry/src/main/java/io/sentry/adapters/ContextsSerializerAdapter.java index 834c04915e..f7ec6b7061 100644 --- a/sentry/src/main/java/io/sentry/adapters/ContextsSerializerAdapter.java +++ b/sentry/src/main/java/io/sentry/adapters/ContextsSerializerAdapter.java @@ -5,8 +5,8 @@ import com.google.gson.JsonParseException; import com.google.gson.JsonSerializationContext; import com.google.gson.JsonSerializer; -import io.sentry.ILogger; import io.sentry.SentryLevel; +import io.sentry.SentryOptions; import io.sentry.protocol.Contexts; import java.lang.reflect.Type; import java.util.Map; @@ -16,10 +16,10 @@ @ApiStatus.Internal public final class ContextsSerializerAdapter implements JsonSerializer { - private final @NotNull ILogger logger; + private final @NotNull SentryOptions options; - public ContextsSerializerAdapter(@NotNull final ILogger logger) { - this.logger = logger; + public ContextsSerializerAdapter(final @NotNull SentryOptions options) { + this.options = options; } @Override @@ -36,7 +36,7 @@ public JsonElement serialize(Contexts src, Type typeOfSrc, JsonSerializationCont object.add(entry.getKey(), element); } } catch (JsonParseException e) { - logger.log(SentryLevel.ERROR, "%s context key isn't serializable."); + options.getLogger().log(SentryLevel.ERROR, "%s context key isn't serializable."); } } return object; diff --git a/sentry/src/main/java/io/sentry/adapters/DateDeserializerAdapter.java b/sentry/src/main/java/io/sentry/adapters/DateDeserializerAdapter.java index d5331f561a..5ff6f5b1e3 100644 --- a/sentry/src/main/java/io/sentry/adapters/DateDeserializerAdapter.java +++ b/sentry/src/main/java/io/sentry/adapters/DateDeserializerAdapter.java @@ -5,8 +5,8 @@ import com.google.gson.JsonElement; import com.google.gson.JsonParseException; import io.sentry.DateUtils; -import io.sentry.ILogger; import io.sentry.SentryLevel; +import io.sentry.SentryOptions; import java.lang.reflect.Type; import java.util.Date; import org.jetbrains.annotations.ApiStatus; @@ -15,10 +15,10 @@ @ApiStatus.Internal public final class DateDeserializerAdapter implements JsonDeserializer { - private final @NotNull ILogger logger; + private final @NotNull SentryOptions options; - public DateDeserializerAdapter(final @NotNull ILogger logger) { - this.logger = logger; + public DateDeserializerAdapter(final @NotNull SentryOptions options) { + this.options = options; } @Override @@ -27,15 +27,19 @@ public Date deserialize(JsonElement json, Type typeOfT, JsonDeserializationConte try { return json == null ? null : DateUtils.getDateTime(json.getAsString()); } catch (Exception e) { - logger.log( - SentryLevel.DEBUG, - "Error when deserializing UTC timestamp format, it might be millis timestamp format.", - e); + options + .getLogger() + .log( + SentryLevel.DEBUG, + "Error when deserializing UTC timestamp format, it might be millis timestamp format.", + e); } try { return DateUtils.getDateTimeWithMillisPrecision(json.getAsString()); } catch (Exception e) { - logger.log(SentryLevel.ERROR, "Error when deserializing millis timestamp format.", e); + options + .getLogger() + .log(SentryLevel.ERROR, "Error when deserializing millis timestamp format.", e); } return null; } diff --git a/sentry/src/main/java/io/sentry/adapters/DateSerializerAdapter.java b/sentry/src/main/java/io/sentry/adapters/DateSerializerAdapter.java index 419b579176..c38e64a7c8 100644 --- a/sentry/src/main/java/io/sentry/adapters/DateSerializerAdapter.java +++ b/sentry/src/main/java/io/sentry/adapters/DateSerializerAdapter.java @@ -5,8 +5,8 @@ import com.google.gson.JsonSerializationContext; import com.google.gson.JsonSerializer; import io.sentry.DateUtils; -import io.sentry.ILogger; import io.sentry.SentryLevel; +import io.sentry.SentryOptions; import java.lang.reflect.Type; import java.util.Date; import org.jetbrains.annotations.ApiStatus; @@ -15,10 +15,10 @@ @ApiStatus.Internal public final class DateSerializerAdapter implements JsonSerializer { - private final @NotNull ILogger logger; + private final @NotNull SentryOptions options; - public DateSerializerAdapter(final @NotNull ILogger logger) { - this.logger = logger; + public DateSerializerAdapter(final @NotNull SentryOptions options) { + this.options = options; } @Override @@ -26,7 +26,7 @@ public JsonElement serialize(Date src, Type typeOfSrc, JsonSerializationContext try { return src == null ? null : new JsonPrimitive(DateUtils.getTimestamp(src)); } catch (Exception e) { - logger.log(SentryLevel.ERROR, "Error when serializing Date", e); + options.getLogger().log(SentryLevel.ERROR, "Error when serializing Date", e); } return null; } diff --git a/sentry/src/main/java/io/sentry/adapters/OrientationDeserializerAdapter.java b/sentry/src/main/java/io/sentry/adapters/OrientationDeserializerAdapter.java index d4fd295ec0..d70e5a60d7 100644 --- a/sentry/src/main/java/io/sentry/adapters/OrientationDeserializerAdapter.java +++ b/sentry/src/main/java/io/sentry/adapters/OrientationDeserializerAdapter.java @@ -4,8 +4,8 @@ import com.google.gson.JsonDeserializer; import com.google.gson.JsonElement; import com.google.gson.JsonParseException; -import io.sentry.ILogger; import io.sentry.SentryLevel; +import io.sentry.SentryOptions; import io.sentry.protocol.Device; import java.lang.reflect.Type; import java.util.Locale; @@ -16,10 +16,10 @@ public final class OrientationDeserializerAdapter implements JsonDeserializer { - private final @NotNull ILogger logger; + private final @NotNull SentryOptions options; - public OrientationDeserializerAdapter(final @NotNull ILogger logger) { - this.logger = logger; + public OrientationDeserializerAdapter(final @NotNull SentryOptions options) { + this.options = options; } @Override @@ -31,7 +31,7 @@ public Device.DeviceOrientation deserialize( ? null : Device.DeviceOrientation.valueOf(json.getAsString().toUpperCase(Locale.ROOT)); } catch (Exception e) { - logger.log(SentryLevel.ERROR, "Error when deserializing DeviceOrientation", e); + options.getLogger().log(SentryLevel.ERROR, "Error when deserializing DeviceOrientation", e); } return null; } diff --git a/sentry/src/main/java/io/sentry/adapters/OrientationSerializerAdapter.java b/sentry/src/main/java/io/sentry/adapters/OrientationSerializerAdapter.java index 4e1ee6c725..0e27c68ff3 100644 --- a/sentry/src/main/java/io/sentry/adapters/OrientationSerializerAdapter.java +++ b/sentry/src/main/java/io/sentry/adapters/OrientationSerializerAdapter.java @@ -4,8 +4,8 @@ import com.google.gson.JsonPrimitive; import com.google.gson.JsonSerializationContext; import com.google.gson.JsonSerializer; -import io.sentry.ILogger; import io.sentry.SentryLevel; +import io.sentry.SentryOptions; import io.sentry.protocol.Device; import java.lang.reflect.Type; import java.util.Locale; @@ -16,10 +16,10 @@ public final class OrientationSerializerAdapter implements JsonSerializer { - private final @NotNull ILogger logger; + private final @NotNull SentryOptions options; - public OrientationSerializerAdapter(final @NotNull ILogger logger) { - this.logger = logger; + public OrientationSerializerAdapter(final @NotNull SentryOptions options) { + this.options = options; } @Override @@ -28,7 +28,7 @@ public JsonElement serialize( try { return src == null ? null : new JsonPrimitive(src.name().toLowerCase(Locale.ROOT)); } catch (Exception e) { - logger.log(SentryLevel.ERROR, "Error when serializing DeviceOrientation", e); + options.getLogger().log(SentryLevel.ERROR, "Error when serializing DeviceOrientation", e); } return null; } diff --git a/sentry/src/main/java/io/sentry/adapters/SentryIdDeserializerAdapter.java b/sentry/src/main/java/io/sentry/adapters/SentryIdDeserializerAdapter.java index 83ed4193b9..e9def47b6f 100644 --- a/sentry/src/main/java/io/sentry/adapters/SentryIdDeserializerAdapter.java +++ b/sentry/src/main/java/io/sentry/adapters/SentryIdDeserializerAdapter.java @@ -4,8 +4,8 @@ import com.google.gson.JsonDeserializer; import com.google.gson.JsonElement; import com.google.gson.JsonParseException; -import io.sentry.ILogger; import io.sentry.SentryLevel; +import io.sentry.SentryOptions; import io.sentry.protocol.SentryId; import java.lang.reflect.Type; import org.jetbrains.annotations.ApiStatus; @@ -14,10 +14,10 @@ @ApiStatus.Internal public final class SentryIdDeserializerAdapter implements JsonDeserializer { - private final @NotNull ILogger logger; + private final @NotNull SentryOptions options; - public SentryIdDeserializerAdapter(final @NotNull ILogger logger) { - this.logger = logger; + public SentryIdDeserializerAdapter(final @NotNull SentryOptions options) { + this.options = options; } @Override @@ -26,7 +26,7 @@ public SentryId deserialize(JsonElement json, Type typeOfT, JsonDeserializationC try { return json == null ? null : new SentryId(json.getAsString()); } catch (Exception e) { - logger.log(SentryLevel.ERROR, "Error when deserializing SentryId", e); + options.getLogger().log(SentryLevel.ERROR, "Error when deserializing SentryId", e); } return null; } diff --git a/sentry/src/main/java/io/sentry/adapters/SentryIdSerializerAdapter.java b/sentry/src/main/java/io/sentry/adapters/SentryIdSerializerAdapter.java index 7cf6efab45..ac10c47e0d 100644 --- a/sentry/src/main/java/io/sentry/adapters/SentryIdSerializerAdapter.java +++ b/sentry/src/main/java/io/sentry/adapters/SentryIdSerializerAdapter.java @@ -4,8 +4,8 @@ import com.google.gson.JsonPrimitive; import com.google.gson.JsonSerializationContext; import com.google.gson.JsonSerializer; -import io.sentry.ILogger; import io.sentry.SentryLevel; +import io.sentry.SentryOptions; import io.sentry.protocol.SentryId; import java.lang.reflect.Type; import org.jetbrains.annotations.ApiStatus; @@ -14,10 +14,10 @@ @ApiStatus.Internal public final class SentryIdSerializerAdapter implements JsonSerializer { - private final @NotNull ILogger logger; + private final @NotNull SentryOptions options; - public SentryIdSerializerAdapter(final @NotNull ILogger logger) { - this.logger = logger; + public SentryIdSerializerAdapter(final @NotNull SentryOptions options) { + this.options = options; } @Override @@ -25,7 +25,7 @@ public JsonElement serialize(SentryId src, Type typeOfSrc, JsonSerializationCont try { return src == null ? null : new JsonPrimitive(src.toString()); } catch (Exception e) { - logger.log(SentryLevel.ERROR, "Error when serializing SentryId", e); + options.getLogger().log(SentryLevel.ERROR, "Error when serializing SentryId", e); } return null; } diff --git a/sentry/src/main/java/io/sentry/adapters/SentryLevelDeserializerAdapter.java b/sentry/src/main/java/io/sentry/adapters/SentryLevelDeserializerAdapter.java index 09f109d5b0..5703fc4406 100644 --- a/sentry/src/main/java/io/sentry/adapters/SentryLevelDeserializerAdapter.java +++ b/sentry/src/main/java/io/sentry/adapters/SentryLevelDeserializerAdapter.java @@ -4,8 +4,8 @@ import com.google.gson.JsonDeserializer; import com.google.gson.JsonElement; import com.google.gson.JsonParseException; -import io.sentry.ILogger; import io.sentry.SentryLevel; +import io.sentry.SentryOptions; import java.lang.reflect.Type; import java.util.Locale; import org.jetbrains.annotations.ApiStatus; @@ -14,10 +14,10 @@ @ApiStatus.Internal public final class SentryLevelDeserializerAdapter implements JsonDeserializer { - private final @NotNull ILogger logger; + private final @NotNull SentryOptions options; - public SentryLevelDeserializerAdapter(final @NotNull ILogger logger) { - this.logger = logger; + public SentryLevelDeserializerAdapter(final @NotNull SentryOptions options) { + this.options = options; } @Override @@ -26,7 +26,7 @@ public SentryLevel deserialize(JsonElement json, Type typeOfT, JsonDeserializati try { return json == null ? null : SentryLevel.valueOf(json.getAsString().toUpperCase(Locale.ROOT)); } catch (Exception e) { - logger.log(SentryLevel.ERROR, "Error when deserializing SentryLevel", e); + options.getLogger().log(SentryLevel.ERROR, "Error when deserializing SentryLevel", e); } return null; } diff --git a/sentry/src/main/java/io/sentry/adapters/SentryLevelSerializerAdapter.java b/sentry/src/main/java/io/sentry/adapters/SentryLevelSerializerAdapter.java index 911f830154..7f044ec7a8 100644 --- a/sentry/src/main/java/io/sentry/adapters/SentryLevelSerializerAdapter.java +++ b/sentry/src/main/java/io/sentry/adapters/SentryLevelSerializerAdapter.java @@ -4,8 +4,8 @@ import com.google.gson.JsonPrimitive; import com.google.gson.JsonSerializationContext; import com.google.gson.JsonSerializer; -import io.sentry.ILogger; import io.sentry.SentryLevel; +import io.sentry.SentryOptions; import java.lang.reflect.Type; import java.util.Locale; import org.jetbrains.annotations.ApiStatus; @@ -14,10 +14,10 @@ @ApiStatus.Internal public final class SentryLevelSerializerAdapter implements JsonSerializer { - private final @NotNull ILogger logger; + private final @NotNull SentryOptions options; - public SentryLevelSerializerAdapter(final @NotNull ILogger logger) { - this.logger = logger; + public SentryLevelSerializerAdapter(final @NotNull SentryOptions options) { + this.options = options; } @Override @@ -25,7 +25,7 @@ public JsonElement serialize(SentryLevel src, Type typeOfSrc, JsonSerializationC try { return src == null ? null : new JsonPrimitive(src.name().toLowerCase(Locale.ROOT)); } catch (Exception e) { - logger.log(SentryLevel.ERROR, "Error when serializing SentryLevel", e); + options.getLogger().log(SentryLevel.ERROR, "Error when serializing SentryLevel", e); } return null; } diff --git a/sentry/src/main/java/io/sentry/adapters/SpanIdDeserializerAdapter.java b/sentry/src/main/java/io/sentry/adapters/SpanIdDeserializerAdapter.java index cecd3364bb..3c076e3e11 100644 --- a/sentry/src/main/java/io/sentry/adapters/SpanIdDeserializerAdapter.java +++ b/sentry/src/main/java/io/sentry/adapters/SpanIdDeserializerAdapter.java @@ -4,8 +4,8 @@ import com.google.gson.JsonDeserializer; import com.google.gson.JsonElement; import com.google.gson.JsonParseException; -import io.sentry.ILogger; import io.sentry.SentryLevel; +import io.sentry.SentryOptions; import io.sentry.SpanId; import java.lang.reflect.Type; import org.jetbrains.annotations.ApiStatus; @@ -14,10 +14,10 @@ @ApiStatus.Internal public final class SpanIdDeserializerAdapter implements JsonDeserializer { - private final @NotNull ILogger logger; + private final @NotNull SentryOptions options; - public SpanIdDeserializerAdapter(final @NotNull ILogger logger) { - this.logger = logger; + public SpanIdDeserializerAdapter(final @NotNull SentryOptions options) { + this.options = options; } @Override @@ -26,7 +26,7 @@ public SpanId deserialize(JsonElement json, Type typeOfT, JsonDeserializationCon try { return json == null ? null : new SpanId(json.getAsString()); } catch (Exception e) { - logger.log(SentryLevel.ERROR, "Error when deserializing SpanId", e); + options.getLogger().log(SentryLevel.ERROR, "Error when deserializing SpanId", e); } return null; } diff --git a/sentry/src/main/java/io/sentry/adapters/SpanIdSerializerAdapter.java b/sentry/src/main/java/io/sentry/adapters/SpanIdSerializerAdapter.java index 78f3db8e88..8b6a36cd9c 100644 --- a/sentry/src/main/java/io/sentry/adapters/SpanIdSerializerAdapter.java +++ b/sentry/src/main/java/io/sentry/adapters/SpanIdSerializerAdapter.java @@ -4,8 +4,8 @@ import com.google.gson.JsonPrimitive; import com.google.gson.JsonSerializationContext; import com.google.gson.JsonSerializer; -import io.sentry.ILogger; import io.sentry.SentryLevel; +import io.sentry.SentryOptions; import io.sentry.SpanId; import java.lang.reflect.Type; import org.jetbrains.annotations.ApiStatus; @@ -14,10 +14,10 @@ @ApiStatus.Internal public final class SpanIdSerializerAdapter implements JsonSerializer { - private final @NotNull ILogger logger; + private final @NotNull SentryOptions options; - public SpanIdSerializerAdapter(final @NotNull ILogger logger) { - this.logger = logger; + public SpanIdSerializerAdapter(final @NotNull SentryOptions options) { + this.options = options; } @Override @@ -25,7 +25,7 @@ public JsonElement serialize(SpanId src, Type typeOfSrc, JsonSerializationContex try { return src == null ? null : new JsonPrimitive(src.toString()); } catch (Exception e) { - logger.log(SentryLevel.ERROR, "Error when serializing SpanId", e); + options.getLogger().log(SentryLevel.ERROR, "Error when serializing SpanId", e); } return null; } diff --git a/sentry/src/main/java/io/sentry/adapters/SpanStatusDeserializerAdapter.java b/sentry/src/main/java/io/sentry/adapters/SpanStatusDeserializerAdapter.java index 772754f01d..393d804a72 100644 --- a/sentry/src/main/java/io/sentry/adapters/SpanStatusDeserializerAdapter.java +++ b/sentry/src/main/java/io/sentry/adapters/SpanStatusDeserializerAdapter.java @@ -4,8 +4,8 @@ import com.google.gson.JsonDeserializer; import com.google.gson.JsonElement; import com.google.gson.JsonParseException; -import io.sentry.ILogger; import io.sentry.SentryLevel; +import io.sentry.SentryOptions; import io.sentry.SpanStatus; import java.lang.reflect.Type; import java.util.Locale; @@ -15,10 +15,10 @@ @ApiStatus.Internal public final class SpanStatusDeserializerAdapter implements JsonDeserializer { - private final @NotNull ILogger logger; + private final @NotNull SentryOptions options; - public SpanStatusDeserializerAdapter(final @NotNull ILogger logger) { - this.logger = logger; + public SpanStatusDeserializerAdapter(final @NotNull SentryOptions options) { + this.options = options; } @Override @@ -27,7 +27,7 @@ public SpanStatus deserialize(JsonElement json, Type typeOfT, JsonDeserializatio try { return json == null ? null : SpanStatus.valueOf(json.getAsString().toUpperCase(Locale.ROOT)); } catch (Exception e) { - logger.log(SentryLevel.ERROR, "Error when deserializing SpanStatus", e); + options.getLogger().log(SentryLevel.ERROR, "Error when deserializing SpanStatus", e); } return null; } diff --git a/sentry/src/main/java/io/sentry/adapters/SpanStatusSerializerAdapter.java b/sentry/src/main/java/io/sentry/adapters/SpanStatusSerializerAdapter.java index b5bba8c148..7b729c0c2c 100644 --- a/sentry/src/main/java/io/sentry/adapters/SpanStatusSerializerAdapter.java +++ b/sentry/src/main/java/io/sentry/adapters/SpanStatusSerializerAdapter.java @@ -4,8 +4,8 @@ import com.google.gson.JsonPrimitive; import com.google.gson.JsonSerializationContext; import com.google.gson.JsonSerializer; -import io.sentry.ILogger; import io.sentry.SentryLevel; +import io.sentry.SentryOptions; import io.sentry.SpanStatus; import java.lang.reflect.Type; import java.util.Locale; @@ -15,10 +15,10 @@ @ApiStatus.Internal public final class SpanStatusSerializerAdapter implements JsonSerializer { - private final @NotNull ILogger logger; + private final @NotNull SentryOptions options; - public SpanStatusSerializerAdapter(final @NotNull ILogger logger) { - this.logger = logger; + public SpanStatusSerializerAdapter(final @NotNull SentryOptions options) { + this.options = options; } @Override @@ -26,7 +26,7 @@ public JsonElement serialize(SpanStatus src, Type typeOfSrc, JsonSerializationCo try { return src == null ? null : new JsonPrimitive(src.name().toLowerCase(Locale.ROOT)); } catch (Exception e) { - logger.log(SentryLevel.ERROR, "Error when serializing SpanStatus", e); + options.getLogger().log(SentryLevel.ERROR, "Error when serializing SpanStatus", e); } return null; } diff --git a/sentry/src/main/java/io/sentry/adapters/TimeZoneDeserializerAdapter.java b/sentry/src/main/java/io/sentry/adapters/TimeZoneDeserializerAdapter.java index 2cd89b4fbb..5cdbd08a06 100644 --- a/sentry/src/main/java/io/sentry/adapters/TimeZoneDeserializerAdapter.java +++ b/sentry/src/main/java/io/sentry/adapters/TimeZoneDeserializerAdapter.java @@ -4,8 +4,8 @@ import com.google.gson.JsonDeserializer; import com.google.gson.JsonElement; import com.google.gson.JsonParseException; -import io.sentry.ILogger; import io.sentry.SentryLevel; +import io.sentry.SentryOptions; import java.lang.reflect.Type; import java.util.TimeZone; import org.jetbrains.annotations.ApiStatus; @@ -14,10 +14,10 @@ @ApiStatus.Internal public final class TimeZoneDeserializerAdapter implements JsonDeserializer { - private final @NotNull ILogger logger; + private final @NotNull SentryOptions options; - public TimeZoneDeserializerAdapter(final @NotNull ILogger logger) { - this.logger = logger; + public TimeZoneDeserializerAdapter(final @NotNull SentryOptions options) { + this.options = options; } @Override @@ -26,7 +26,7 @@ public TimeZone deserialize(JsonElement json, Type typeOfT, JsonDeserializationC try { return json == null ? null : TimeZone.getTimeZone(json.getAsString()); } catch (Exception e) { - logger.log(SentryLevel.ERROR, "Error when deserializing TimeZone", e); + options.getLogger().log(SentryLevel.ERROR, "Error when deserializing TimeZone", e); } return null; } diff --git a/sentry/src/main/java/io/sentry/adapters/TimeZoneSerializerAdapter.java b/sentry/src/main/java/io/sentry/adapters/TimeZoneSerializerAdapter.java index 4c53562299..cd1934bf5a 100644 --- a/sentry/src/main/java/io/sentry/adapters/TimeZoneSerializerAdapter.java +++ b/sentry/src/main/java/io/sentry/adapters/TimeZoneSerializerAdapter.java @@ -4,8 +4,8 @@ import com.google.gson.JsonPrimitive; import com.google.gson.JsonSerializationContext; import com.google.gson.JsonSerializer; -import io.sentry.ILogger; import io.sentry.SentryLevel; +import io.sentry.SentryOptions; import java.lang.reflect.Type; import java.util.TimeZone; import org.jetbrains.annotations.ApiStatus; @@ -14,10 +14,10 @@ @ApiStatus.Internal public final class TimeZoneSerializerAdapter implements JsonSerializer { - private final @NotNull ILogger logger; + private final @NotNull SentryOptions options; - public TimeZoneSerializerAdapter(final @NotNull ILogger logger) { - this.logger = logger; + public TimeZoneSerializerAdapter(final @NotNull SentryOptions options) { + this.options = options; } @Override @@ -25,7 +25,7 @@ public JsonElement serialize(TimeZone src, Type typeOfSrc, JsonSerializationCont try { return src == null ? null : new JsonPrimitive(src.getID()); } catch (Exception e) { - logger.log(SentryLevel.ERROR, "Error when serializing TimeZone", e); + options.getLogger().log(SentryLevel.ERROR, "Error when serializing TimeZone", e); } return null; } diff --git a/sentry/src/test/java/io/sentry/GsonSerializerTest.kt b/sentry/src/test/java/io/sentry/GsonSerializerTest.kt index 4cacd1371c..b0f3f88302 100644 --- a/sentry/src/test/java/io/sentry/GsonSerializerTest.kt +++ b/sentry/src/test/java/io/sentry/GsonSerializerTest.kt @@ -4,6 +4,7 @@ import com.google.gson.JsonObject import com.google.gson.JsonParser import com.google.gson.JsonPrimitive import com.nhaarman.mockitokotlin2.any +import com.nhaarman.mockitokotlin2.check import com.nhaarman.mockitokotlin2.eq import com.nhaarman.mockitokotlin2.mock import com.nhaarman.mockitokotlin2.verify @@ -36,7 +37,14 @@ class GsonSerializerTest { private class Fixture { val logger: ILogger = mock() - val serializer = GsonSerializer(logger, EnvelopeReader()) + val serializer: ISerializer + + init { + val options = SentryOptions() + options.setLogger(logger) + options.setDebug(true) + serializer = GsonSerializer(options, EnvelopeReader()) + } } private lateinit var fixture: Fixture @@ -561,6 +569,20 @@ class GsonSerializerTest { assertNull(element.asJsonObject["spans"]) } + @Test + fun `gson serializer uses logger set on SentryOptions`() { + val logger = mock() + val options = SentryOptions() + options.setLogger(logger) + options.setDebug(true) + whenever(logger.isEnabled(any())).thenReturn(true) + + (options.serializer as GsonSerializer).serialize(mapOf("key" to "val"), mock()) + verify(logger).log(any(), check { + assertTrue(it.startsWith("Serializing object:")) + }, any()) + } + private fun assertSessionData(expectedSession: Session?) { assertNotNull(expectedSession) assertEquals(UUID.fromString("c81d4e2e-bcf2-11e6-869b-7df92533d2db"), expectedSession.sessionId) diff --git a/sentry/src/test/java/io/sentry/SentryClientTest.kt b/sentry/src/test/java/io/sentry/SentryClientTest.kt index 1fe7408304..2958378b45 100644 --- a/sentry/src/test/java/io/sentry/SentryClientTest.kt +++ b/sentry/src/test/java/io/sentry/SentryClientTest.kt @@ -59,7 +59,7 @@ class SentryClientTest { } setDebug(true) setDiagnosticLevel(SentryLevel.DEBUG) - setSerializer(GsonSerializer(mock(), envelopeReader)) + setSerializer(GsonSerializer(this, envelopeReader)) setLogger(mock()) maxAttachmentSize = this@Fixture.maxAttachmentSize setTransportFactory(factory) diff --git a/sentry/src/test/java/io/sentry/SessionAdapterTest.kt b/sentry/src/test/java/io/sentry/SessionAdapterTest.kt index ee4e4d1727..10be123222 100644 --- a/sentry/src/test/java/io/sentry/SessionAdapterTest.kt +++ b/sentry/src/test/java/io/sentry/SessionAdapterTest.kt @@ -11,7 +11,7 @@ import kotlin.test.assertNull class SessionAdapterTest { - private val serializer = GsonSerializer(mock(), EnvelopeReader()) + private val serializer = GsonSerializer(SentryOptions().apply { setLogger(mock()) }, EnvelopeReader()) @Test fun `null timestamp does not serialize `() { diff --git a/sentry/src/test/java/io/sentry/cache/CacheStrategyTest.kt b/sentry/src/test/java/io/sentry/cache/CacheStrategyTest.kt index 2af0da7597..35ae00ad7e 100644 --- a/sentry/src/test/java/io/sentry/cache/CacheStrategyTest.kt +++ b/sentry/src/test/java/io/sentry/cache/CacheStrategyTest.kt @@ -97,7 +97,7 @@ class CacheStrategyTest { @Test fun `move init flag if state is ok`() { val options = SentryOptions().apply { - setSerializer(GsonSerializer(mock(), envelopeReader)) + setSerializer(GsonSerializer(this, envelopeReader)) } val sut = fixture.getSUT(3, options) @@ -177,7 +177,7 @@ class CacheStrategyTest { private fun getOptionsWithRealSerializer(): SentryOptions { return SentryOptions().apply { - setSerializer(GsonSerializer(mock(), envelopeReader)) + setSerializer(GsonSerializer(this, envelopeReader)) } } }