Skip to content
39 changes: 29 additions & 10 deletions sentry/api/sentry.api
Original file line number Diff line number Diff line change
Expand Up @@ -3042,17 +3042,17 @@ public final class io/sentry/SentryLockReason$JsonKeys {
}

public final class io/sentry/SentryLogEvent : io/sentry/JsonSerializable, io/sentry/JsonUnknown {
public fun <init> (Lio/sentry/protocol/SentryId;Lio/sentry/SentryDate;Ljava/lang/String;Lio/sentry/SentryLevel;)V
public fun <init> (Lio/sentry/protocol/SentryId;Ljava/lang/Double;Ljava/lang/String;Lio/sentry/SentryLevel;)V
public fun <init> (Lio/sentry/protocol/SentryId;Lio/sentry/SentryDate;Ljava/lang/String;Lio/sentry/SentryLogLevel;)V
public fun <init> (Lio/sentry/protocol/SentryId;Ljava/lang/Double;Ljava/lang/String;Lio/sentry/SentryLogLevel;)V
public fun getAttributes ()Ljava/util/Map;
public fun getBody ()Ljava/lang/String;
public fun getLevel ()Lio/sentry/SentryLevel;
public fun getLevel ()Lio/sentry/SentryLogLevel;
public fun getTimestamp ()Ljava/lang/Double;
public fun getUnknown ()Ljava/util/Map;
public fun serialize (Lio/sentry/ObjectWriter;Lio/sentry/ILogger;)V
public fun setAttributes (Ljava/util/Map;)V
public fun setBody (Ljava/lang/String;)V
public fun setLevel (Lio/sentry/SentryLevel;)V
public fun setLevel (Lio/sentry/SentryLogLevel;)V
public fun setTimestamp (Ljava/lang/Double;)V
public fun setUnknown (Ljava/util/Map;)V
}
Expand Down Expand Up @@ -3110,6 +3110,25 @@ public final class io/sentry/SentryLogEvents$JsonKeys {
public fun <init> ()V
}

public final class io/sentry/SentryLogLevel : java/lang/Enum, io/sentry/JsonSerializable {
public static final field DEBUG Lio/sentry/SentryLogLevel;
public static final field ERROR Lio/sentry/SentryLogLevel;
public static final field FATAL Lio/sentry/SentryLogLevel;
public static final field INFO Lio/sentry/SentryLogLevel;
public static final field TRACE Lio/sentry/SentryLogLevel;
public static final field WARN Lio/sentry/SentryLogLevel;
public fun getSeverityNumber ()I
public fun serialize (Lio/sentry/ObjectWriter;Lio/sentry/ILogger;)V
public static fun valueOf (Ljava/lang/String;)Lio/sentry/SentryLogLevel;
public static fun values ()[Lio/sentry/SentryLogLevel;
}

public final class io/sentry/SentryLogLevel$Deserializer : io/sentry/JsonDeserializer {
public fun <init> ()V
public fun deserialize (Lio/sentry/ObjectReader;Lio/sentry/ILogger;)Lio/sentry/SentryLogLevel;
public synthetic fun deserialize (Lio/sentry/ObjectReader;Lio/sentry/ILogger;)Ljava/lang/Object;
}

public final class io/sentry/SentryLongDate : io/sentry/SentryDate {
public fun <init> (J)V
public fun nanoTimestamp ()J
Expand Down Expand Up @@ -4685,8 +4704,8 @@ public abstract interface class io/sentry/logger/ILoggerApi {
public abstract fun error (Ljava/lang/String;[Ljava/lang/Object;)V
public abstract fun fatal (Ljava/lang/String;[Ljava/lang/Object;)V
public abstract fun info (Ljava/lang/String;[Ljava/lang/Object;)V
public abstract fun log (Lio/sentry/SentryLevel;Lio/sentry/SentryDate;Ljava/lang/String;Lio/sentry/Hint;[Ljava/lang/Object;)V
public abstract fun log (Lio/sentry/SentryLevel;Ljava/lang/String;[Ljava/lang/Object;)V
public abstract fun log (Lio/sentry/SentryLogLevel;Lio/sentry/SentryDate;Ljava/lang/String;Lio/sentry/Hint;[Ljava/lang/Object;)V
public abstract fun log (Lio/sentry/SentryLogLevel;Ljava/lang/String;[Ljava/lang/Object;)V
public abstract fun trace (Ljava/lang/String;[Ljava/lang/Object;)V
public abstract fun warn (Ljava/lang/String;[Ljava/lang/Object;)V
}
Expand All @@ -4702,8 +4721,8 @@ public final class io/sentry/logger/LoggerApi : io/sentry/logger/ILoggerApi {
public fun error (Ljava/lang/String;[Ljava/lang/Object;)V
public fun fatal (Ljava/lang/String;[Ljava/lang/Object;)V
public fun info (Ljava/lang/String;[Ljava/lang/Object;)V
public fun log (Lio/sentry/SentryLevel;Lio/sentry/SentryDate;Ljava/lang/String;Lio/sentry/Hint;[Ljava/lang/Object;)V
public fun log (Lio/sentry/SentryLevel;Ljava/lang/String;[Ljava/lang/Object;)V
public fun log (Lio/sentry/SentryLogLevel;Lio/sentry/SentryDate;Ljava/lang/String;Lio/sentry/Hint;[Ljava/lang/Object;)V
public fun log (Lio/sentry/SentryLogLevel;Ljava/lang/String;[Ljava/lang/Object;)V
public fun trace (Ljava/lang/String;[Ljava/lang/Object;)V
public fun warn (Ljava/lang/String;[Ljava/lang/Object;)V
}
Expand All @@ -4722,8 +4741,8 @@ public final class io/sentry/logger/NoOpLoggerApi : io/sentry/logger/ILoggerApi
public fun fatal (Ljava/lang/String;[Ljava/lang/Object;)V
public static fun getInstance ()Lio/sentry/logger/NoOpLoggerApi;
public fun info (Ljava/lang/String;[Ljava/lang/Object;)V
public fun log (Lio/sentry/SentryLevel;Lio/sentry/SentryDate;Ljava/lang/String;Lio/sentry/Hint;[Ljava/lang/Object;)V
public fun log (Lio/sentry/SentryLevel;Ljava/lang/String;[Ljava/lang/Object;)V
public fun log (Lio/sentry/SentryLogLevel;Lio/sentry/SentryDate;Ljava/lang/String;Lio/sentry/Hint;[Ljava/lang/Object;)V
public fun log (Lio/sentry/SentryLogLevel;Ljava/lang/String;[Ljava/lang/Object;)V
public fun trace (Ljava/lang/String;[Ljava/lang/Object;)V
public fun warn (Ljava/lang/String;[Ljava/lang/Object;)V
}
Expand Down
14 changes: 7 additions & 7 deletions sentry/src/main/java/io/sentry/SentryLogEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public final class SentryLogEvent implements JsonUnknown, JsonSerializable {
private @NotNull SentryId traceId;
private @NotNull Double timestamp;
private @NotNull String body;
private @NotNull SentryLevel level;
private @NotNull SentryLogLevel level;

private @Nullable Map<String, SentryLogEventAttributeValue> attributes;
private @Nullable Map<String, Object> unknown;
Expand All @@ -24,15 +24,15 @@ public SentryLogEvent(
final @NotNull SentryId traceId,
final @NotNull SentryDate timestamp,
final @NotNull String body,
final @NotNull SentryLevel level) {
final @NotNull SentryLogLevel level) {
this(traceId, DateUtils.nanosToSeconds(timestamp.nanoTimestamp()), body, level);
}

public SentryLogEvent(
final @NotNull SentryId traceId,
final @NotNull Double timestamp,
final @NotNull String body,
final @NotNull SentryLevel level) {
final @NotNull SentryLogLevel level) {
this.traceId = traceId;
this.timestamp = timestamp;
this.body = body;
Expand All @@ -56,11 +56,11 @@ public void setBody(@NotNull String body) {
this.body = body;
}

public @NotNull SentryLevel getLevel() {
public @NotNull SentryLogLevel getLevel() {
return level;
}

public void setLevel(final @NotNull SentryLevel level) {
public void setLevel(final @NotNull SentryLogLevel level) {
this.level = level;
}

Expand Down Expand Up @@ -123,7 +123,7 @@ public static final class Deserializer implements JsonDeserializer<SentryLogEven
@Nullable SentryId traceId = null;
@Nullable Double timestamp = null;
@Nullable String body = null;
@Nullable SentryLevel level = null;
@Nullable SentryLogLevel level = null;
@Nullable Map<String, SentryLogEventAttributeValue> attributes = null;

reader.beginObject();
Expand All @@ -140,7 +140,7 @@ public static final class Deserializer implements JsonDeserializer<SentryLogEven
body = reader.nextStringOrNull();
break;
case JsonKeys.LEVEL:
level = reader.nextOrNull(logger, new SentryLevel.Deserializer());
level = reader.nextOrNull(logger, new SentryLogLevel.Deserializer());
break;
case JsonKeys.ATTRIBUTES:
attributes =
Expand Down
40 changes: 40 additions & 0 deletions sentry/src/main/java/io/sentry/SentryLogLevel.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package io.sentry;

import java.io.IOException;
import java.util.Locale;
import org.jetbrains.annotations.NotNull;

/** the SentryLevel for Logs */
public enum SentryLogLevel implements JsonSerializable {
TRACE(1),
DEBUG(5),
INFO(9),
WARN(13),
ERROR(17),
FATAL(21);

private final int severityNumber;

private SentryLogLevel(int severityNumber) {
this.severityNumber = severityNumber;
}

public int getSeverityNumber() {
return severityNumber;
}

@Override
public void serialize(final @NotNull ObjectWriter writer, final @NotNull ILogger logger)
throws IOException {
writer.value(name().toLowerCase(Locale.ROOT));
}

public static final class Deserializer implements JsonDeserializer<SentryLogLevel> {

@Override
public @NotNull SentryLogLevel deserialize(
@NotNull ObjectReader reader, @NotNull ILogger logger) throws Exception {
return SentryLogLevel.valueOf(reader.nextString().toUpperCase(Locale.ROOT));
}
}
}
6 changes: 3 additions & 3 deletions sentry/src/main/java/io/sentry/logger/ILoggerApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import io.sentry.Hint;
import io.sentry.SentryDate;
import io.sentry.SentryLevel;
import io.sentry.SentryLogLevel;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
Expand All @@ -22,10 +22,10 @@ public interface ILoggerApi {

void fatal(final @Nullable String message, @Nullable Object... args);

void log(@NotNull SentryLevel level, @Nullable String message, @Nullable Object... args);
void log(@NotNull SentryLogLevel level, @Nullable String message, @Nullable Object... args);

void log(
@NotNull SentryLevel level,
@NotNull SentryLogLevel level,
@Nullable SentryDate timestamp,
@Nullable String message,
final @Nullable Hint hint,
Expand Down
19 changes: 10 additions & 9 deletions sentry/src/main/java/io/sentry/logger/LoggerApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import io.sentry.SentryLevel;
import io.sentry.SentryLogEvent;
import io.sentry.SentryLogEventAttributeValue;
import io.sentry.SentryLogLevel;
import io.sentry.SentryOptions;
import io.sentry.SpanId;
import io.sentry.clientreport.DiscardReason;
Expand All @@ -33,45 +34,45 @@ public LoggerApi(final @NotNull Scopes scopes) {
@Override
public void trace(final @Nullable String message, final @Nullable Object... args) {
// TODO SentryLevel.TRACE does not exists yet so we just report it as DEBUG for now
log(SentryLevel.DEBUG, message, args);
log(SentryLogLevel.DEBUG, message, args);
}

@Override
public void debug(final @Nullable String message, final @Nullable Object... args) {
log(SentryLevel.DEBUG, message, args);
log(SentryLogLevel.DEBUG, message, args);
}

@Override
public void info(final @Nullable String message, final @Nullable Object... args) {
log(SentryLevel.INFO, message, args);
log(SentryLogLevel.INFO, message, args);
}

@Override
public void warn(final @Nullable String message, final @Nullable Object... args) {
log(SentryLevel.WARNING, message, args);
log(SentryLogLevel.WARN, message, args);
}

@Override
public void error(final @Nullable String message, final @Nullable Object... args) {
log(SentryLevel.ERROR, message, args);
log(SentryLogLevel.ERROR, message, args);
}

@Override
public void fatal(final @Nullable String message, final @Nullable Object... args) {
log(SentryLevel.FATAL, message, args);
log(SentryLogLevel.FATAL, message, args);
}

@Override
public void log(
final @NotNull SentryLevel level,
final @NotNull SentryLogLevel level,
final @Nullable String message,
final @Nullable Object... args) {
log(level, null, message, null, args);
}

@Override
public void log(
final @NotNull SentryLevel level,
final @NotNull SentryLogLevel level,
final @Nullable SentryDate timestamp,
final @Nullable String message,
final @Nullable Hint hint,
Expand All @@ -81,7 +82,7 @@ public void log(

@SuppressWarnings("AnnotateFormatMethod")
private void captureLog(
final @NotNull SentryLevel level,
final @NotNull SentryLogLevel level,
final @Nullable SentryDate timestamp,
final @Nullable Hint hint,
final @Nullable String message,
Expand Down
7 changes: 4 additions & 3 deletions sentry/src/main/java/io/sentry/logger/NoOpLoggerApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import io.sentry.Hint;
import io.sentry.SentryDate;
import io.sentry.SentryLevel;
import io.sentry.SentryLogLevel;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
Expand Down Expand Up @@ -49,13 +49,14 @@ public void fatal(@Nullable String message, @Nullable Object... args) {
}

@Override
public void log(@NotNull SentryLevel level, @Nullable String message, @Nullable Object... args) {
public void log(
@NotNull SentryLogLevel level, @Nullable String message, @Nullable Object... args) {
// do nothing
}

@Override
public void log(
@NotNull SentryLevel level,
@NotNull SentryLogLevel level,
@Nullable SentryDate timestamp,
@Nullable String message,
final @Nullable Hint hint,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import io.sentry.ILogger
import io.sentry.JsonObjectReader
import io.sentry.JsonObjectWriter
import io.sentry.JsonSerializable
import io.sentry.SentryLevel
import io.sentry.SentryLogEvent
import io.sentry.SentryLogEventAttributeValue
import io.sentry.SentryLogEvents
import io.sentry.SentryLogLevel
import org.junit.Test
import org.mockito.kotlin.mock
import java.io.StringReader
Expand All @@ -26,7 +26,7 @@ class SentryLogsSerializationTest {
SentryId("5c1f73d39486827b9e60ceb1fc23277a"),
DateUtils.dateToSeconds(DateUtils.getDateTime("2004-04-10T18:24:03.000Z")),
"42e6bd2a-c45e-414d-8066-ed5196fbc686",
SentryLevel.INFO
SentryLogLevel.INFO
).also {
it.attributes = mutableMapOf(
"sentry.sdk.name" to SentryLogEventAttributeValue("string", "sentry.java.spring-boot.jakarta"),
Expand Down
4 changes: 2 additions & 2 deletions sentry/src/test/java/io/sentry/transport/RateLimiterTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ import io.sentry.SentryEnvelope
import io.sentry.SentryEnvelopeHeader
import io.sentry.SentryEnvelopeItem
import io.sentry.SentryEvent
import io.sentry.SentryLevel
import io.sentry.SentryLogEvent
import io.sentry.SentryLogEvents
import io.sentry.SentryLogLevel
import io.sentry.SentryLongDate
import io.sentry.SentryOptions
import io.sentry.SentryOptionsManipulator
Expand Down Expand Up @@ -354,7 +354,7 @@ class RateLimiterTest {
fixture.serializer,
SentryLogEvents(
listOf(
SentryLogEvent(SentryId(), SentryLongDate(0), "hello", SentryLevel.INFO)
SentryLogEvent(SentryId(), SentryLongDate(0), "hello", SentryLogLevel.INFO)
)
)
)
Expand Down
Loading