From b3cac816c66b991e6cca3e5297d1b0d56c837e49 Mon Sep 17 00:00:00 2001 From: ryanhamshire Date: Sat, 16 May 2015 19:17:11 -0700 Subject: [PATCH] Better logging for secondary storage problems. --- .../GriefPrevention/CustomLogger.java | 4 +++- .../GriefPrevention/DatabaseDataStore.java | 13 ++++++++----- .../GriefPrevention/FlatFileDataStore.java | 19 ++++++++++++------- 3 files changed, 23 insertions(+), 13 deletions(-) diff --git a/src/me/ryanhamshire/GriefPrevention/CustomLogger.java b/src/me/ryanhamshire/GriefPrevention/CustomLogger.java index a34793a..11cc9fb 100644 --- a/src/me/ryanhamshire/GriefPrevention/CustomLogger.java +++ b/src/me/ryanhamshire/GriefPrevention/CustomLogger.java @@ -80,6 +80,7 @@ class CustomLogger private boolean isEnabledType(CustomLogEntryTypes entryType) { + if(entryType == CustomLogEntryTypes.Exception) return true; if(entryType == CustomLogEntryTypes.SocialActivity && !GriefPrevention.instance.config_logs_socialEnabled) return false; if(entryType == CustomLogEntryTypes.SuspiciousActivity && !GriefPrevention.instance.config_logs_suspiciousEnabled) return false; if(entryType == CustomLogEntryTypes.AdminActivity && !GriefPrevention.instance.config_logs_adminEnabled) return false; @@ -185,5 +186,6 @@ enum CustomLogEntryTypes SocialActivity, SuspiciousActivity, AdminActivity, - Debug + Debug, + Exception } diff --git a/src/me/ryanhamshire/GriefPrevention/DatabaseDataStore.java b/src/me/ryanhamshire/GriefPrevention/DatabaseDataStore.java index b41c549..b7fd596 100644 --- a/src/me/ryanhamshire/GriefPrevention/DatabaseDataStore.java +++ b/src/me/ryanhamshire/GriefPrevention/DatabaseDataStore.java @@ -18,6 +18,8 @@ package me.ryanhamshire.GriefPrevention; +import java.io.PrintWriter; +import java.io.StringWriter; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; @@ -514,9 +516,9 @@ public class DatabaseDataStore extends DataStore } catch(SQLException e) { - GriefPrevention.AddLogEntry("Unable to retrieve data for player " + playerID.toString() + ". Details:"); - GriefPrevention.AddLogEntry(e.getMessage()); - e.printStackTrace(); + StringWriter errors = new StringWriter(); + e.printStackTrace(new PrintWriter(errors)); + GriefPrevention.AddLogEntry(playerID + " " + errors.toString(), CustomLogEntryTypes.Exception); } return playerData; @@ -548,8 +550,9 @@ public class DatabaseDataStore extends DataStore } catch(SQLException e) { - GriefPrevention.AddLogEntry("Unable to save data for player " + playerID.toString() + ". Details:"); - GriefPrevention.AddLogEntry(e.getMessage()); + StringWriter errors = new StringWriter(); + e.printStackTrace(new PrintWriter(errors)); + GriefPrevention.AddLogEntry(playerID + " " + errors.toString(), CustomLogEntryTypes.Exception); } } diff --git a/src/me/ryanhamshire/GriefPrevention/FlatFileDataStore.java b/src/me/ryanhamshire/GriefPrevention/FlatFileDataStore.java index 62f58a9..1d0417a 100644 --- a/src/me/ryanhamshire/GriefPrevention/FlatFileDataStore.java +++ b/src/me/ryanhamshire/GriefPrevention/FlatFileDataStore.java @@ -94,7 +94,9 @@ public class FlatFileDataStore extends DataStore } catch(Exception e) { - GriefPrevention.AddLogEntry("Unable to load group bonus block data from file \"" + file.getName() + "\": " + e.getMessage()); + StringWriter errors = new StringWriter(); + e.printStackTrace(new PrintWriter(errors)); + GriefPrevention.AddLogEntry(errors.toString(), CustomLogEntryTypes.Exception); } try @@ -340,8 +342,9 @@ public class FlatFileDataStore extends DataStore } else { - GriefPrevention.AddLogEntry("Unable to load data for claim \"" + files[i].getName() + "\": " + e.toString()); - e.printStackTrace(); + StringWriter errors = new StringWriter(); + e.printStackTrace(new PrintWriter(errors)); + GriefPrevention.AddLogEntry(files[i].getName() + " " + errors.toString(), CustomLogEntryTypes.Exception); } } @@ -384,8 +387,9 @@ public class FlatFileDataStore extends DataStore //if any problem, log it catch(Exception e) { - GriefPrevention.AddLogEntry("Unexpected exception saving data for claim \"" + claimID + "\": " + e.toString()); - e.printStackTrace(); + StringWriter errors = new StringWriter(); + e.printStackTrace(new PrintWriter(errors)); + GriefPrevention.AddLogEntry(claimID + " " + errors.toString(), CustomLogEntryTypes.Exception); } //close the file @@ -542,8 +546,9 @@ public class FlatFileDataStore extends DataStore //if last attempt failed, log information about the problem if(needRetry) { - GriefPrevention.AddLogEntry("Retry attempts exhausted. Unable to load data for player \"" + playerID.toString() + "\": " + latestException.toString()); - latestException.printStackTrace(); + StringWriter errors = new StringWriter(); + latestException.printStackTrace(new PrintWriter(errors)); + GriefPrevention.AddLogEntry(playerID + " " + errors.toString(), CustomLogEntryTypes.Exception); } }