Better logging for secondary storage problems.

This commit is contained in:
ryanhamshire 2015-05-16 19:17:11 -07:00
parent e23d8a956a
commit b3cac816c6
3 changed files with 23 additions and 13 deletions

View File

@ -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
}

View File

@ -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);
}
}

View File

@ -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);
}
}