diff --git a/patches/server/0006-Pufferfish-Sentry.patch b/patches/server/0006-Pufferfish-Sentry.patch index 7b48a4cc0..68ec60b6a 100644 --- a/patches/server/0006-Pufferfish-Sentry.patch +++ b/patches/server/0006-Pufferfish-Sentry.patch @@ -8,10 +8,10 @@ Original project: https://github.com/pufferfish-gg/Pufferfish diff --git a/src/main/java/gg/pufferfish/pufferfish/sentry/PufferfishSentryAppender.java b/src/main/java/gg/pufferfish/pufferfish/sentry/PufferfishSentryAppender.java new file mode 100644 -index 0000000000000000000000000000000000000000..a8779d7c5bee9869e214f1e5550faedd785c78d9 +index 0000000000000000000000000000000000000000..0d1d6751cb6e9d6f282d343b58a80ca8640e259a --- /dev/null +++ b/src/main/java/gg/pufferfish/pufferfish/sentry/PufferfishSentryAppender.java -@@ -0,0 +1,130 @@ +@@ -0,0 +1,133 @@ +package gg.pufferfish.pufferfish.sentry; + +import com.google.common.reflect.TypeToken; @@ -32,19 +32,22 @@ index 0000000000000000000000000000000000000000..a8779d7c5bee9869e214f1e5550faedd +import org.apache.logging.log4j.core.Logger; +import org.apache.logging.log4j.core.appender.AbstractAppender; +import org.apache.logging.log4j.core.filter.AbstractFilter; ++import org.dreeam.leaf.config.modules.misc.SentryDSN; + +public class PufferfishSentryAppender extends AbstractAppender { + + private static final org.apache.logging.log4j.Logger logger = LogManager.getLogger(PufferfishSentryAppender.class.getSimpleName()); + private static final Gson GSON = new Gson(); ++ private final Level logLevel; + -+ public PufferfishSentryAppender() { ++ public PufferfishSentryAppender(Level logLevel) { + super("PufferfishSentryAdapter", new SentryFilter(), null); ++ this.logLevel = logLevel; + } + + @Override + public void append(LogEvent logEvent) { -+ if (logEvent.getThrown() != null && logEvent.getLevel().isMoreSpecificThan(Level.WARN)) { ++ if (logEvent.getLevel().isMoreSpecificThan(logLevel) && (logEvent.getThrown() != null || !SentryDSN.onlyLogThrown)) { + try { + logException(logEvent); + } catch (Exception e) { @@ -144,13 +147,14 @@ index 0000000000000000000000000000000000000000..a8779d7c5bee9869e214f1e5550faedd +} diff --git a/src/main/java/gg/pufferfish/pufferfish/sentry/SentryManager.java b/src/main/java/gg/pufferfish/pufferfish/sentry/SentryManager.java new file mode 100644 -index 0000000000000000000000000000000000000000..e9da86f5c655552ae3453e0c31ab1f1e63eb1ad8 +index 0000000000000000000000000000000000000000..1fc08518f9cc2b6840b5074f181aefc693c3074b --- /dev/null +++ b/src/main/java/gg/pufferfish/pufferfish/sentry/SentryManager.java -@@ -0,0 +1,39 @@ +@@ -0,0 +1,44 @@ +package gg.pufferfish.pufferfish.sentry; + +import io.sentry.Sentry; ++import org.apache.logging.log4j.Level; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + @@ -164,10 +168,14 @@ index 0000000000000000000000000000000000000000..e9da86f5c655552ae3453e0c31ab1f1e + + private static boolean initialized = false; + -+ public static synchronized void init() { ++ public static synchronized void init(Level logLevel) { + if (initialized) { + return; + } ++ if (logLevel == null) { ++ logger.error("Invalid log level, defaulting to WARN."); ++ logLevel = Level.WARN; ++ } + try { + initialized = true; + @@ -176,7 +184,7 @@ index 0000000000000000000000000000000000000000..e9da86f5c655552ae3453e0c31ab1f1e + options.setMaxBreadcrumbs(100); + }); + -+ PufferfishSentryAppender appender = new PufferfishSentryAppender(); ++ PufferfishSentryAppender appender = new PufferfishSentryAppender(logLevel); + appender.start(); + ((org.apache.logging.log4j.core.Logger) LogManager.getRootLogger()).addAppender(appender); + logger.info("Sentry logging started!"); @@ -189,35 +197,43 @@ index 0000000000000000000000000000000000000000..e9da86f5c655552ae3453e0c31ab1f1e +} diff --git a/src/main/java/org/dreeam/leaf/config/modules/misc/SentryDSN.java b/src/main/java/org/dreeam/leaf/config/modules/misc/SentryDSN.java new file mode 100644 -index 0000000000000000000000000000000000000000..cf5fa3b30460e07f0f380ead36bb0650d5450304 +index 0000000000000000000000000000000000000000..29e0a2aa4a6d6228f88c47053556cbd2457edc20 --- /dev/null +++ b/src/main/java/org/dreeam/leaf/config/modules/misc/SentryDSN.java -@@ -0,0 +1,28 @@ +@@ -0,0 +1,36 @@ +package org.dreeam.leaf.config.modules.misc; + ++import org.apache.logging.log4j.Level; +import org.dreeam.leaf.config.ConfigModules; +import org.dreeam.leaf.config.EnumConfigCategory; + +public class SentryDSN extends ConfigModules { + + public String getBasePath() { -+ return EnumConfigCategory.MISC.getBaseKeyName() + ".sentry-dsn"; ++ return EnumConfigCategory.MISC.getBaseKeyName() + ".sentry"; + } + + public static String sentryDsn = ""; ++ public static String logLevel = "WARN"; ++ public static boolean onlyLogThrown = true; + + @Override + public void onLoaded() { + String sentryEnvironment = System.getenv("SENTRY_DSN"); -+ String sentryConfig = config.getString(getBasePath(), sentryDsn, """ ++ String sentryConfig = config.getString(getBasePath() + ".dsn", sentryDsn, """ + Sentry DSN for improved error logging, leave blank to disable, + Obtain from https://sentry.io/"""); + + sentryDsn = sentryEnvironment == null + ? sentryConfig + : sentryEnvironment; ++ logLevel = config.getString(getBasePath() + ".log-level", logLevel, """ ++ Logs with a level higher than or equal to this level will be recorded"""); ++ onlyLogThrown = config.getBoolean(getBasePath() + ".only-log-thrown", onlyLogThrown, """ ++ Only log with a Throwable will be recorded after enabling this"""); ++ + if (sentryDsn != null && !sentryDsn.isBlank()) { -+ gg.pufferfish.pufferfish.sentry.SentryManager.init(); ++ gg.pufferfish.pufferfish.sentry.SentryManager.init(Level.getLevel(logLevel)); + } + } +}