Logger fixes.

This commit is contained in:
Steven Lawson 2013-08-21 17:42:21 -04:00
parent 23907ef7e4
commit 6ba8dcaa58
2 changed files with 29 additions and 21 deletions

View File

@ -2,10 +2,13 @@ package me.StevenLawson.TotalFreedomMod;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.bukkit.Bukkit;
public class TFM_Log
{
private static final Logger FALLBACK_LOGGER = Logger.getLogger("Minecraft-Server");
private static Logger serverLogger = null;
private static Logger pluginLogger = null;
private TFM_Log()
{
throw new AssertionError();
@ -47,34 +50,33 @@ public class TFM_Log
private static void log(Level level, String message, boolean raw)
{
LoggerType.getLogger(raw).log(level, message);
getLogger(raw).log(level, message);
}
private static void log(Level level, Throwable throwable)
{
LoggerType.SERVER.getLogger().log(level, null, throwable);
getLogger(false).log(level, null, throwable);
}
private static enum LoggerType
public static void setServerLogger(Logger logger)
{
SERVER(Bukkit.getLogger()),
PLUGIN(TotalFreedomMod.plugin.getLogger());
//
private final Logger logger;
serverLogger = logger;
}
private LoggerType(Logger logger)
public static void setPluginLogger(Logger logger)
{
pluginLogger = logger;
}
private static Logger getLogger(boolean raw)
{
if (raw || pluginLogger == null)
{
this.logger = logger;
return (serverLogger != null ? serverLogger : FALLBACK_LOGGER);
}
public Logger getLogger()
else
{
return logger;
}
public static Logger getLogger(boolean getRawLogger)
{
return (getRawLogger ? SERVER.getLogger() : PLUGIN.getLogger());
return pluginLogger;
}
}
}

View File

@ -4,7 +4,6 @@ import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.*;
import java.util.logging.Logger;
import me.StevenLawson.TotalFreedomMod.Commands.TFM_Command;
import me.StevenLawson.TotalFreedomMod.Commands.TFM_CommandLoader;
import me.StevenLawson.TotalFreedomMod.Listener.*;
@ -63,14 +62,21 @@ public class TotalFreedomMod extends JavaPlugin
public static List<String> permbanned_ips = new ArrayList<String>();
@Override
public void onEnable()
public void onLoad()
{
TotalFreedomMod.plugin = this;
TotalFreedomMod.plugin_file = plugin.getFile();
TotalFreedomMod.pluginName = plugin.getDescription().getName();
setAppProperties();
TFM_Log.setPluginLogger(this.getLogger());
TFM_Log.setServerLogger(this.getServer().getLogger());
setAppProperties();
}
@Override
public void onEnable()
{
TFM_Log.info("Version: " + TotalFreedomMod.pluginVersion + "." + TotalFreedomMod.buildNumber + " by Madgeek1450 and DarthSalamon");
loadSuperadminConfig();