client: make error logging opt out (#1953)

client: make error logging opt out
This commit is contained in:
Owain van Brakel
2019-11-08 15:57:46 +01:00
committed by GitHub
33 changed files with 197 additions and 13 deletions

View File

@@ -27,6 +27,7 @@ package net.runelite.client;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import javax.annotation.Nullable;
public class RuneLiteProperties
{
@@ -40,7 +41,7 @@ public class RuneLiteProperties
private static final String GITHUB_LINK = "runelite.github.link";
private static final String WIKI_LINK = "runelite.wiki.link";
private static final String PATREON_LINK = "runelite.patreon.link";
private static final String LAUNCHER_VERSION_PROPERTY = "runelite.launcher.version";
private static final String LAUNCHER_VERSION_PROPERTY = "launcher.version";
private static final String TROUBLESHOOTING_LINK = "runelite.wiki.troubleshooting.link";
private static final String BUILDING_LINK = "runelite.wiki.building.link";
private static final String DNS_CHANGE_LINK = "runelite.dnschange.link";
@@ -129,4 +130,11 @@ public class RuneLiteProperties
{
return properties.getProperty(DNS_CHANGE_LINK);
}
@Nullable
public static String getLauncherVersion()
{
String launcherVersion = properties.getProperty(LAUNCHER_VERSION_PROPERTY);
return launcherVersion.equals("-1") ? null : launcherVersion;
}
}

View File

@@ -50,6 +50,29 @@ public interface OpenOSRSConfig extends Config
}
}
@ConfigTitleSection(
keyName = "logTitle",
name = "Error data",
description = "",
position = 1
)
default Title logTitle()
{
return new Title();
}
@ConfigItem(
position = 3,
keyName = "shareLogs",
name = "Anonymous error data",
description = "Share anonymous error data with the OpenOSRS developers",
titleSection = "logTitle"
)
default boolean shareLogs()
{
return true;
}
@ConfigTitleSection(
keyName = "pluginsTitle",
name = "Plugins",

View File

@@ -10,9 +10,12 @@ import io.sentry.Sentry;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import javax.inject.Inject;
import javax.inject.Singleton;
import lombok.extern.slf4j.Slf4j;
import net.runelite.api.events.Event;
import net.runelite.client.RuneLiteProperties;
import net.runelite.client.config.OpenOSRSConfig;
@Slf4j
@Singleton
@@ -22,6 +25,9 @@ public class EventBus implements EventBusInterface
private Map<Class<?>, Relay<Object>> subjectList = new HashMap<>();
private Map<Object, CompositeDisposable> subscriptionsMap = new HashMap<>();
@Inject
private OpenOSRSConfig openOSRSConfig;
@NonNull
private <T> Relay<Object> getSubject(Class<T> eventClass)
{
@@ -53,7 +59,15 @@ public class EventBus implements EventBusInterface
Disposable disposable = getSubject(eventClass)
.filter(Objects::nonNull) // Filter out null objects, better safe than sorry
.cast(eventClass) // Cast it for easier usage
.subscribe(action, Sentry::capture);
.subscribe(action, error ->
{
log.error("Exception in eventbus", error);
if (RuneLiteProperties.getLauncherVersion() != null && openOSRSConfig.shareLogs())
{
Sentry.capture(error);
}
});
getCompositeDisposable(lifecycle).add(disposable);
subscriptionList.put(lifecycle, eventClass);
@@ -72,7 +86,15 @@ public class EventBus implements EventBusInterface
.cast(eventClass) // Cast it for easier usage
.take(takeUntil)
.doFinally(() -> unregister(lifecycle))
.subscribe(action, Sentry::capture);
.subscribe(action, error ->
{
log.error("Exception in eventbus", error);
if (RuneLiteProperties.getLauncherVersion() != null && openOSRSConfig.shareLogs())
{
Sentry.capture(error);
}
});
getCompositeDisposable(lifecycle).add(disposable);
subscriptionList.put(lifecycle, eventClass);

View File

@@ -359,8 +359,7 @@ public class ObjectIndicatorsPlugin extends Plugin implements KeyListener
&& (worldPoint.getY() & (REGION_SIZE - 1)) == objectPoint.getRegionY())
{
// Transform object to get the name which matches against what we've stored
if (getObjectDefinition(object.getId()) != null &&
objectPoint.getName().equals(getObjectDefinition(object.getId()).getName()))
if (objectPoint.getName().equals(getObjectDefinition(object.getId()).getName()))
{
log.debug("Marking object {} due to matching {}", object, objectPoint);
objects.add(object);