Added BentoBox#logStacktrace(Throwable)

This commit is contained in:
Florian CUNY 2019-02-13 11:03:26 +01:00
parent d5750ca509
commit a1d8c69556
3 changed files with 15 additions and 3 deletions

View File

@ -2,6 +2,7 @@ package world.bentobox.bentobox;
import java.util.Optional;
import org.apache.commons.lang.exception.ExceptionUtils;
import org.bukkit.Bukkit;
import org.bukkit.generator.ChunkGenerator;
import org.bukkit.plugin.PluginManager;
@ -347,6 +348,16 @@ public class BentoBox extends JavaPlugin {
getLogger().severe(() -> error);
}
/**
* Logs the stacktrace of a Throwable that was thrown by an error.
* It should be used preferably instead of {@link Throwable#printStackTrace()} as it does not risk exposing sensitive information.
* @param throwable the Throwable that was thrown by an error.
* @since 1.3.0
*/
public void logStacktrace(@NonNull Throwable throwable) {
logError(ExceptionUtils.getStackTrace(throwable));
}
public void logWarning(String warning) {
getLogger().warning(() -> warning);
}

View File

@ -5,6 +5,7 @@ import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;
import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.util.Util;
import java.io.BufferedReader;
@ -39,8 +40,8 @@ public class GitHubConnector {
contributorData = getData("contributors");
releasesData = getData("releases");
} catch (IOException e) {
e.printStackTrace();
// TODO better logging and do not override data instead
BentoBox.getInstance().logStacktrace(e);
// TODO do not override data instead
return;
}

View File

@ -178,7 +178,7 @@ public class AddonsManager {
addon.setState(Addon.State.ERROR);
plugin.logError("Skipping " + addon.getDescription().getName() + " due to an unhandled exception...");
// Send stacktrace, required for addon development
plugin.logError(ExceptionUtils.getStackTrace(throwable));
plugin.logStacktrace(throwable);
}
/**