diff options
author | Luck <git@lucko.me> | 2024-10-26 11:08:49 +0100 |
---|---|---|
committer | Luck <git@lucko.me> | 2024-10-26 11:08:49 +0100 |
commit | ef507b147a8a0c7d209b62303de50fb895851c82 (patch) | |
tree | 5598bacf0dd887914921c0186cc0c3d48df7ab1d /spark-common/src/main/java/me/lucko/spark/common/command | |
parent | c58ddcfc37971178087d7637979a2c17e9a44d09 (diff) | |
download | spark-ef507b147a8a0c7d209b62303de50fb895851c82.tar.gz spark-ef507b147a8a0c7d209b62303de50fb895851c82.tar.bz2 spark-ef507b147a8a0c7d209b62303de50fb895851c82.zip |
Improve error logging in various places
Diffstat (limited to 'spark-common/src/main/java/me/lucko/spark/common/command')
3 files changed, 14 insertions, 11 deletions
diff --git a/spark-common/src/main/java/me/lucko/spark/common/command/modules/HealthModule.java b/spark-common/src/main/java/me/lucko/spark/common/command/modules/HealthModule.java index fbf79ef..6bfdd0e 100644 --- a/spark-common/src/main/java/me/lucko/spark/common/command/modules/HealthModule.java +++ b/spark-common/src/main/java/me/lucko/spark/common/command/modules/HealthModule.java @@ -57,6 +57,7 @@ import java.util.Locale; import java.util.Map; import java.util.Set; import java.util.function.Consumer; +import java.util.logging.Level; import static net.kyori.adventure.text.Component.empty; import static net.kyori.adventure.text.Component.space; @@ -249,7 +250,7 @@ public class HealthModule implements CommandModule { platform.getActivityLog().addToLog(Activity.urlActivity(resp.senderData(), System.currentTimeMillis(), "Health report", url)); } catch (Exception e) { resp.broadcastPrefixed(text("An error occurred whilst uploading the data.", RED)); - e.printStackTrace(); + platform.getPlugin().log(Level.SEVERE, "An error occurred whilst uploading data", e); } } diff --git a/spark-common/src/main/java/me/lucko/spark/common/command/modules/HeapAnalysisModule.java b/spark-common/src/main/java/me/lucko/spark/common/command/modules/HeapAnalysisModule.java index 54f7df1..9a97ca7 100644 --- a/spark-common/src/main/java/me/lucko/spark/common/command/modules/HeapAnalysisModule.java +++ b/spark-common/src/main/java/me/lucko/spark/common/command/modules/HeapAnalysisModule.java @@ -44,6 +44,7 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicLong; import java.util.function.Consumer; import java.util.function.LongConsumer; +import java.util.logging.Level; import static net.kyori.adventure.text.Component.text; import static net.kyori.adventure.text.format.NamedTextColor.GOLD; @@ -85,7 +86,7 @@ public class HeapAnalysisModule implements CommandModule { heapDump = HeapDumpSummary.createNew(); } catch (Exception e) { resp.broadcastPrefixed(text("An error occurred whilst inspecting the heap.", RED)); - e.printStackTrace(); + platform.getPlugin().log(Level.SEVERE, "An error occurred whilst inspecting the heap.", e); return; } @@ -110,7 +111,7 @@ public class HeapAnalysisModule implements CommandModule { platform.getActivityLog().addToLog(Activity.urlActivity(resp.senderData(), System.currentTimeMillis(), "Heap dump summary", url)); } catch (Exception e) { resp.broadcastPrefixed(text("An error occurred whilst uploading the data. Attempting to save to disk instead.", RED)); - e.printStackTrace(); + platform.getPlugin().log(Level.SEVERE, "An error occurred whilst uploading the data.", e); saveToFile = true; } } @@ -131,7 +132,7 @@ public class HeapAnalysisModule implements CommandModule { platform.getActivityLog().addToLog(Activity.fileActivity(resp.senderData(), System.currentTimeMillis(), "Heap dump summary", file.toString())); } catch (IOException e) { resp.broadcastPrefixed(text("An error occurred whilst saving the data.", RED)); - e.printStackTrace(); + platform.getPlugin().log(Level.SEVERE, "An error occurred whilst saving the data.", e); } } @@ -153,7 +154,7 @@ public class HeapAnalysisModule implements CommandModule { HeapDump.dumpHeap(file, liveOnly); } catch (Exception e) { resp.broadcastPrefixed(text("An error occurred whilst creating a heap dump.", RED)); - e.printStackTrace(); + platform.getPlugin().log(Level.SEVERE, "An error occurred whilst creating a heap dump.", e); return; } @@ -180,7 +181,7 @@ public class HeapAnalysisModule implements CommandModule { try { heapDumpCompress(platform, resp, file, compressionMethod); } catch (IOException e) { - e.printStackTrace(); + platform.getPlugin().log(Level.SEVERE, "An error occurred whilst compressing the heap dump.", e); } } } diff --git a/spark-common/src/main/java/me/lucko/spark/common/command/modules/SamplerModule.java b/spark-common/src/main/java/me/lucko/spark/common/command/modules/SamplerModule.java index cc7d56b..d65172b 100644 --- a/spark-common/src/main/java/me/lucko/spark/common/command/modules/SamplerModule.java +++ b/spark-common/src/main/java/me/lucko/spark/common/command/modules/SamplerModule.java @@ -59,6 +59,7 @@ import java.util.concurrent.CompletableFuture; import java.util.concurrent.TimeUnit; import java.util.function.Consumer; import java.util.function.Supplier; +import java.util.logging.Level; import static net.kyori.adventure.text.Component.empty; import static net.kyori.adventure.text.Component.space; @@ -277,8 +278,8 @@ public class SamplerModule implements CommandModule { // send message if profiling fails future.whenCompleteAsync((s, throwable) -> { if (throwable != null) { - resp.broadcastPrefixed(text("Profiler operation failed unexpectedly. Error: " + throwable.toString(), RED)); - throwable.printStackTrace(); + resp.broadcastPrefixed(text("Profiler operation failed unexpectedly. Error: " + throwable, RED)); + platform.getPlugin().log(Level.SEVERE, "Profiler operation failed unexpectedly", throwable); } }); @@ -439,7 +440,7 @@ public class SamplerModule implements CommandModule { platform.getActivityLog().addToLog(Activity.urlActivity(resp.senderData(), System.currentTimeMillis(), "Profiler", url)); } catch (Exception e) { resp.broadcastPrefixed(text("An error occurred whilst uploading the results. Attempting to save to disk instead.", RED)); - e.printStackTrace(); + platform.getPlugin().log(Level.WARNING, "Error whilst uploading profiler results", e); saveToFile = true; } } @@ -456,7 +457,7 @@ public class SamplerModule implements CommandModule { platform.getActivityLog().addToLog(Activity.fileActivity(resp.senderData(), System.currentTimeMillis(), "Profiler", file.toString())); } catch (IOException e) { resp.broadcastPrefixed(text("An error occurred whilst saving the data.", RED)); - e.printStackTrace(); + platform.getPlugin().log(Level.WARNING, "Error whilst saving profiler results", e); } } } @@ -498,7 +499,7 @@ public class SamplerModule implements CommandModule { platform.getActivityLog().addToLog(Activity.urlActivity(resp.senderData(), System.currentTimeMillis(), "Profiler (live)", url)); } catch (Exception e) { resp.replyPrefixed(text("An error occurred whilst opening the live profiler.", RED)); - e.printStackTrace(); + platform.getPlugin().log(Level.WARNING, "Error whilst opening live profiler", e); } } |