Removed Logger

This commit is contained in:
Jonathan Williams 2015-01-22 23:18:38 -08:00
parent d5ddb9c640
commit 08078c1622
15 changed files with 46 additions and 234 deletions

View File

@ -18,7 +18,6 @@ import mineplex.core.common.util.Callback;
import mineplex.core.common.util.NautHashMap;
import mineplex.core.common.util.UUIDFetcher;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.logger.Logger;
import mineplex.core.timing.TimingManager;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
@ -155,7 +154,6 @@ public class CoreClientManager extends MiniPlugin
}
catch(Exception exception)
{
Logger.Instance.log(exception);
event.disallow(Result.KICK_OTHER, "Error retrieving information from web, please retry in a minute.");
System.out.println(exception.getMessage());
}

View File

@ -5,7 +5,6 @@ import java.sql.PreparedStatement;
import java.sql.SQLException;
import mineplex.core.database.DBPool;
import mineplex.core.logger.Logger;
import org.bukkit.craftbukkit.v1_7_R4.entity.CraftPlayer;
import org.bukkit.entity.Player;
@ -35,7 +34,6 @@ public class AntiHackRepository
catch (Exception exception)
{
exception.printStackTrace();
Logger.Instance.log(exception);
}
finally
{
@ -78,7 +76,6 @@ public class AntiHackRepository
catch (Exception exception)
{
exception.printStackTrace();
Logger.Instance.log(exception);
}
finally
{

View File

@ -10,7 +10,6 @@ import java.util.Iterator;
import mineplex.core.common.util.NautHashMap;
import mineplex.core.database.column.Column;
import mineplex.core.logger.Logger;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
@ -64,14 +63,17 @@ public abstract class RepositoryBase implements Listener
protected Connection getConnection()
{
try
synchronized (_connectionLock)
{
if (_connection == null)
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
}
catch (SQLException e)
{
e.printStackTrace();
try
{
if (_connection == null)
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
}
catch (SQLException e)
{
e.printStackTrace();
}
}
return _connection;
@ -246,12 +248,6 @@ public abstract class RepositoryBase implements Listener
{
_failedQueue.put(databaseRunnable, runnableMessage);
}
Logger.Instance.log(errorPreMessage + runnableMessage);
}
else
{
Logger.Instance.log("Abandoning database call : " + runnableMessage);
}
}
@ -264,6 +260,32 @@ public abstract class RepositoryBase implements Listener
processFailedQueue();
}
@EventHandler
public void validateConnection(UpdateEvent event)
{
if (event.getType() != UpdateType.MIN_01)
return;
Bukkit.getScheduler().runTaskAsynchronously(Plugin, new Runnable()
{
public void run()
{
synchronized (_connectionLock)
{
try
{
if (_connection == null || !_connection.isValid(5))
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
}
catch (SQLException e)
{
e.printStackTrace();
}
}
}
});
}
private void processFailedQueue()
{
synchronized (_queueLock)

View File

@ -16,7 +16,6 @@ import mineplex.core.donation.Donor;
import mineplex.core.donation.repository.token.GemRewardToken;
import mineplex.core.donation.repository.token.PurchaseToken;
import mineplex.core.donation.repository.token.UnknownPurchaseToken;
import mineplex.core.logger.Logger;
import mineplex.core.server.remotecall.AsyncJsonWebCall;
import mineplex.core.server.remotecall.JsonWebCall;
import mineplex.core.server.util.TransactionResponse;
@ -188,7 +187,6 @@ public class DonationRepository extends RepositoryBase
{
if (executeUpdate(UPDATE_ACCOUNT_GOLD, new ColumnInt("gold", gold), new ColumnVarChar("uuid", 100, uuid)) < 1)
{
Logger.Instance.log("Account gold wasn't updated for " + name);
callback.run(false);
}
else

View File

@ -1,87 +0,0 @@
package mineplex.core.logger;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin;
public class Logger
{
public static Logger Instance;
private static JavaPlugin _plugin;
private LoggerRepository _repository;
public static void initialize(JavaPlugin plugin)
{
_plugin = plugin;
Instance = new Logger(plugin);
}
public Logger(JavaPlugin plugin)
{
setupConfigValues(plugin);
_repository = new LoggerRepository(plugin.getConfig().getString("log.connectionurl"), plugin.getConfig().getString("serverstatus.name"));
Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler()
{
@Override
public void uncaughtException(Thread t, Throwable e)
{
log(e);
e.printStackTrace();
}
});
}
private void setupConfigValues(JavaPlugin plugin)
{
try
{
plugin.getConfig().addDefault("log.connectionurl", "jdbc:mysql://sqlstats.mineplex.com:3306/Mineplex?autoReconnect=true&failOverReadOnly=false&maxReconnects=10");
plugin.getConfig().set("log.connectionurl", plugin.getConfig().getString("log.connectionurl"));
plugin.saveConfig();
}
catch (Exception e)
{
e.printStackTrace();
}
}
public void log(final String message)
{
System.out.println(message);
Bukkit.getServer().getScheduler().runTaskAsynchronously(_plugin, new Runnable()
{
public void run()
{
_repository.saveLog(message);
}
});
}
public void log(Throwable exception)
{
final List<String> messages = new ArrayList<String>();
messages.add("[Exception Start]" + exception.getMessage());
for (StackTraceElement element : exception.getStackTrace())
{
messages.add(element.toString());
}
messages.add("[Exception End]");
Bukkit.getServer().getScheduler().runTaskAsynchronously(_plugin, new Runnable()
{
public void run()
{
_repository.saveLog(messages.toArray(new String[0]));
}
});
}
}

View File

@ -1,106 +0,0 @@
package mineplex.core.logger;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
public class LoggerRepository
{
private static Object _connectionLock = new Object();
private String _connectionString;
private String _userName = "root";
private String _password = "tAbechAk3wR7tuTh";
private static String CREATE_LOG_TABLE = "CREATE TABLE IF NOT EXISTS errorLog (id INT NOT NULL AUTO_INCREMENT, server VARCHAR(256), message VARCHAR(256), date LONG, PRIMARY KEY (id));";
private static String INSERT_LOG = "INSERT INTO errorLog (server, message, date) VALUES (?, ?, now());";
private Connection _connection = null;
private String _serverName;
public LoggerRepository(String connectionUrl, String serverName)
{
_connectionString = connectionUrl;
_serverName = serverName;
initialize();
}
public void initialize()
{
PreparedStatement preparedStatement = null;
try
{
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
// Create table
preparedStatement = _connection.prepareStatement(CREATE_LOG_TABLE);
preparedStatement.execute();
}
catch (Exception exception)
{
exception.printStackTrace();
}
finally
{
if (preparedStatement != null)
{
try
{
preparedStatement.close();
}
catch (SQLException e)
{
e.printStackTrace();
}
}
}
}
public void saveLog(String...message)
{
PreparedStatement preparedStatement = null;
try
{
synchronized (_connectionLock)
{
if (_connection.isClosed())
{
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
}
preparedStatement = _connection.prepareStatement(INSERT_LOG);
for (String msg : message)
{
preparedStatement.setString(1, _serverName);
preparedStatement.setString(2, msg.substring(0, Math.min(257, msg.length())));
preparedStatement.addBatch();
}
preparedStatement.executeBatch();
}
}
catch (Exception exception)
{
exception.printStackTrace();
}
finally
{
if (preparedStatement != null)
{
try
{
preparedStatement.close();
}
catch (SQLException e)
{
e.printStackTrace();
}
}
}
}
}

View File

@ -9,7 +9,6 @@ import mineplex.core.explosion.Explosion;
import mineplex.core.friend.FriendManager;
import mineplex.core.inventory.InventoryManager;
import mineplex.core.itemstack.ItemStackFactory;
import mineplex.core.logger.Logger;
import mineplex.core.memory.MemoryFix;
import mineplex.core.message.MessageManager;
import mineplex.core.monitor.LagMeter;
@ -48,7 +47,7 @@ public class Clans extends JavaPlugin
String webServerAddress = getConfig().getString(WEB_CONFIG);
Logger.initialize(this);
//Logger.initialize(this);
//Static Modules
CommandCenter.Initialize(this);
@ -69,7 +68,7 @@ public class Clans extends JavaPlugin
new Spawn(this, serverStatusManager.getCurrentServerName());
Teleport teleport = new Teleport(this);
Portal portal = new Portal(this, _clientManager, serverStatusManager.getCurrentServerName());
new FileUpdater(this, portal);
new FileUpdater(this, portal, serverStatusManager.getCurrentServerName(), serverStatusManager.getRegion());
Punish punish = new Punish(this, webServerAddress, _clientManager);

View File

@ -18,7 +18,6 @@ import mineplex.core.energy.Energy;
import mineplex.core.friend.FriendManager;
import mineplex.core.hologram.HologramManager;
import mineplex.core.itemstack.ItemStackFactory;
import mineplex.core.logger.Logger;
import mineplex.core.memory.MemoryFix;
import mineplex.core.message.MessageManager;
import mineplex.core.monitor.LagMeter;
@ -70,7 +69,7 @@ public class Hub extends JavaPlugin implements IRelation
String webServerAddress = getConfig().getString(WEB_CONFIG);
Logger.initialize(this);
//Logger.initialize(this);
//Static Modules
CommandCenter.Initialize(this);
@ -110,7 +109,7 @@ public class Hub extends JavaPlugin implements IRelation
new ServerManager(this, clientManager, donationManager, portal, partyManager, serverStatusManager, hubManager, new StackerManager(hubManager), queueManager);
new Chat(this, clientManager, preferenceManager, serverStatusManager.getCurrentServerName());
new MemoryFix(this);
new FileUpdater(this, portal);
new FileUpdater(this, portal, serverStatusManager.getCurrentServerName(), serverStatusManager.getRegion());
new CustomTagFix(this, packetHandler);
//new Replay(this, packetHandler);
new PersonalServerManager(this, clientManager);

View File

@ -8,7 +8,6 @@ import org.bukkit.event.player.PlayerInteractEntityEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import mineplex.core.MiniPlugin;
import mineplex.core.logger.Logger;
import mineplex.core.map.Map;
import mineplex.core.common.Rank;
import mineplex.core.common.util.UtilGear;
@ -36,7 +35,6 @@ public class MapManager extends MiniPlugin
}
catch (Exception ex)
{
Logger.Instance.log(ex);
System.out.println("[MapManager] Player Join exception");
throw ex;
}

View File

@ -12,7 +12,6 @@ import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.MiniPlugin;
import mineplex.core.account.CoreClientManager;
import mineplex.core.logger.Logger;
import mineplex.core.preferences.PreferencesManager;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
@ -70,7 +69,6 @@ public class PartyManager extends MiniPlugin
}
catch (Exception ex)
{
Logger.Instance.log(ex);
throw ex;
}
}

View File

@ -42,7 +42,6 @@ import mineplex.core.common.util.UtilTime;
import mineplex.core.common.util.UtilTime.TimeUnit;
import mineplex.core.donation.DonationManager;
import mineplex.core.itemstack.ItemStackFactory;
import mineplex.core.logger.Logger;
import mineplex.core.portal.Portal;
import mineplex.core.recharge.Recharge;
import mineplex.core.shop.ShopBase;
@ -202,7 +201,6 @@ public class ServerManager extends MiniPlugin
}
catch (Exception exception)
{
Logger.Instance.log(exception);
exception.printStackTrace();
}
@ -647,7 +645,6 @@ public class ServerManager extends MiniPlugin
}
catch (Exception e)
{
Logger.Instance.log(e);
System.out.println("ServerManager - Error parsing servers file : " + e.getMessage());
}
finally

View File

@ -39,7 +39,9 @@ public class ServerSorter implements Comparator<ServerInfo>
if (Integer.parseInt(a.Name.split("-")[1]) < Integer.parseInt(b.Name.split("-")[1]))
return -1;
else if (Integer.parseInt(a.Name.split("-")[1]) > Integer.parseInt(b.Name.split("-")[1]))
return 1;
return 1;
return 0;
}
}

View File

@ -15,7 +15,6 @@ import mineplex.core.common.Rank;
import mineplex.core.common.util.C;
import mineplex.core.common.util.UtilTime;
import mineplex.core.donation.DonationManager;
import mineplex.core.logger.Logger;
import mineplex.core.shop.item.IButton;
import mineplex.core.shop.item.ShopItem;
import mineplex.core.shop.page.ShopPageBase;
@ -64,7 +63,6 @@ public class ServerNpcPage extends ShopPageBase<ServerManager, ServerNpcShop> im
}
catch (Exception exception)
{
Logger.Instance.log(exception);
exception.printStackTrace();
}

View File

@ -59,7 +59,7 @@ public class StaffServer extends JavaPlugin
Portal portal = new Portal(this, clientManager, serverStatusManager.getCurrentServerName());
new Chat(this, clientManager, preferenceManager, serverStatusManager.getCurrentServerName());
new MemoryFix(this);
new FileUpdater(this, portal);
new FileUpdater(this, portal, serverStatusManager.getCurrentServerName(), serverStatusManager.getRegion());
new CustomerSupport(this, clientManager, donationManager, new SalesPackageManager(this, clientManager, donationManager, new InventoryManager(this, clientManager), new StatsManager(this, clientManager)));
//new Password(this, serverStatusManager.getCurrentServerName());

View File

@ -23,7 +23,6 @@ import mineplex.core.gadget.GadgetManager;
import mineplex.core.hologram.HologramManager;
import mineplex.core.inventory.InventoryManager;
import mineplex.core.itemstack.ItemStackFactory;
import mineplex.core.logger.Logger;
import mineplex.core.memory.MemoryFix;
import mineplex.core.message.MessageManager;
import mineplex.core.monitor.LagMeter;
@ -72,7 +71,7 @@ public class Arcade extends JavaPlugin
String webServerAddress = getConfig().getString(WEB_CONFIG);
Logger.initialize(this);
//Logger.initialize(this);
//Static Modules
CommandCenter.Initialize(this);
@ -94,7 +93,7 @@ public class Arcade extends JavaPlugin
new Spawn(this, serverStatusManager.getCurrentServerName());
Teleport teleport = new Teleport(this);
Portal portal = new Portal(this, _clientManager, serverStatusManager.getCurrentServerName());
new FileUpdater(this, portal);
new FileUpdater(this, portal, serverStatusManager.getCurrentServerName(), serverStatusManager.getRegion());
PacketHandler packetHandler = new PacketHandler(this);
DisguiseManager disguiseManager = new DisguiseManager(this, packetHandler);