Added TFM_Log class to organize logging. !!STILL UNSTABLE!!

Will complete JeromSar merge next commit, using these loggers.
This commit is contained in:
Steven Lawson 2012-09-15 13:01:43 -04:00
parent 7d5b52b24e
commit fce0ca3498
11 changed files with 100 additions and 61 deletions

View File

@ -4,7 +4,7 @@ import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import me.StevenLawson.TotalFreedomMod.TFM_Log;
import me.StevenLawson.TotalFreedomMod.TFM_Util;
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
import org.bukkit.ChatColor;
@ -103,7 +103,7 @@ public class Command_saconfig extends TFM_Command
}
catch (IOException ex)
{
log.log(Level.SEVERE, null, ex);
TFM_Log.severe(ex);
}
}
else if (args[0].equalsIgnoreCase("delete") || args[0].equalsIgnoreCase("del") || args[0].equalsIgnoreCase("remove"))
@ -157,7 +157,7 @@ public class Command_saconfig extends TFM_Command
}
catch (IOException ex)
{
log.log(Level.SEVERE, null, ex);
TFM_Log.severe(ex);
}
}
else

View File

@ -2,7 +2,7 @@ package me.StevenLawson.TotalFreedomMod.Commands;
import java.io.File;
import java.io.IOException;
import java.util.logging.Level;
import me.StevenLawson.TotalFreedomMod.TFM_Log;
import me.StevenLawson.TotalFreedomMod.TFM_Util;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
@ -45,7 +45,7 @@ public class Command_ziptool extends TFM_Command
}
catch (IOException ex)
{
log.log(Level.SEVERE, null, ex);
TFM_Log.severe(ex);
}
sender.sendMessage("Zip finished.");
@ -68,7 +68,7 @@ public class Command_ziptool extends TFM_Command
}
catch (IOException ex)
{
log.log(Level.SEVERE, null, ex);
TFM_Log.severe(ex);
}
sender.sendMessage("Unzip finished.");

View File

@ -1,7 +1,7 @@
package me.StevenLawson.TotalFreedomMod.Commands;
import java.util.List;
import java.util.logging.Logger;
import me.StevenLawson.TotalFreedomMod.TFM_Log;
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
import org.bukkit.ChatColor;
import org.bukkit.Server;
@ -13,7 +13,6 @@ public class TFM_Command
{
protected TotalFreedomMod plugin;
protected Server server;
protected static final Logger log = Logger.getLogger("Minecraft");
public TFM_Command()
{
@ -21,7 +20,7 @@ public class TFM_Command
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{
log.severe("Command Error: Command not implemented: " + cmd.getName());
TFM_Log.severe("Command Error: Command not implemented: " + cmd.getName());
sender.sendMessage(ChatColor.RED + "Command Error: Command not implemented: " + cmd.getName());
return false;
}

View File

@ -1,6 +1,6 @@
package me.StevenLawson.TotalFreedomMod.Listener;
import java.util.logging.Logger;
import me.StevenLawson.TotalFreedomMod.TFM_Log;
import me.StevenLawson.TotalFreedomMod.TFM_UserInfo;
import me.StevenLawson.TotalFreedomMod.TFM_Util;
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
@ -17,7 +17,6 @@ import org.bukkit.inventory.ItemStack;
public class TFM_BlockListener implements Listener
{
private final TotalFreedomMod plugin;
private static final Logger log = Logger.getLogger("Minecraft");
public TFM_BlockListener(TotalFreedomMod instance)
{
@ -152,7 +151,7 @@ public class TFM_BlockListener implements Listener
{
if (TotalFreedomMod.allowLavaPlace)
{
log.info(String.format("%s placed lava @ %s", p.getName(), TFM_Util.formatLocation(event.getBlock().getLocation())));
TFM_Log.info(String.format("%s placed lava @ %s", p.getName(), TFM_Util.formatLocation(event.getBlock().getLocation())));
p.getInventory().clear(p.getInventory().getHeldItemSlot());
}
@ -171,7 +170,7 @@ public class TFM_BlockListener implements Listener
{
if (TotalFreedomMod.allowWaterPlace)
{
log.info(String.format("%s placed water @ %s", p.getName(), TFM_Util.formatLocation(event.getBlock().getLocation())));
TFM_Log.info(String.format("%s placed water @ %s", p.getName(), TFM_Util.formatLocation(event.getBlock().getLocation())));
p.getInventory().clear(p.getInventory().getHeldItemSlot());
}
@ -189,7 +188,7 @@ public class TFM_BlockListener implements Listener
{
if (TotalFreedomMod.allowFirePlace)
{
log.info(String.format("%s placed fire @ %s", p.getName(), TFM_Util.formatLocation(event.getBlock().getLocation())));
TFM_Log.info(String.format("%s placed fire @ %s", p.getName(), TFM_Util.formatLocation(event.getBlock().getLocation())));
p.getInventory().clear(p.getInventory().getHeldItemSlot());
}
@ -207,7 +206,7 @@ public class TFM_BlockListener implements Listener
{
if (TotalFreedomMod.allowExplosions)
{
log.info(String.format("%s placed TNT @ %s", p.getName(), TFM_Util.formatLocation(event.getBlock().getLocation())));
TFM_Log.info(String.format("%s placed TNT @ %s", p.getName(), TFM_Util.formatLocation(event.getBlock().getLocation())));
p.getInventory().clear(p.getInventory().getHeldItemSlot());
}

View File

@ -3,8 +3,6 @@ package me.StevenLawson.TotalFreedomMod.Listener;
import java.text.SimpleDateFormat;
import java.util.Iterator;
import java.util.Map.Entry;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.regex.Pattern;
import me.StevenLawson.TotalFreedomMod.*;
import net.minecraft.server.BanEntry;
@ -27,7 +25,6 @@ import org.bukkit.util.Vector;
public class TFM_PlayerListener implements Listener
{
private final TotalFreedomMod plugin;
private static final Logger log = Logger.getLogger("Minecraft");
private static final SimpleDateFormat date_format = new SimpleDateFormat("yyyy-MM-dd \'at\' HH:mm:ss z");
public TFM_PlayerListener(TotalFreedomMod instance)
@ -337,7 +334,7 @@ public class TFM_PlayerListener implements Listener
}
catch (Exception ex)
{
log.log(Level.SEVERE, null, ex);
TFM_Log.severe(ex);
}
}
@ -365,7 +362,7 @@ public class TFM_PlayerListener implements Listener
if (TotalFreedomMod.preprocessLogEnabled)
{
log.info(String.format("[PREPROCESS_COMMAND] %s(%s): %s", p.getName(), ChatColor.stripColor(p.getDisplayName()), command));
TFM_Log.info(String.format("[PREPROCESS_COMMAND] %s(%s): %s", p.getName(), ChatColor.stripColor(p.getDisplayName()), command), true);
}
command = command.toLowerCase().trim();

View File

@ -0,0 +1,54 @@
package me.StevenLawson.TotalFreedomMod;
import java.util.logging.Level;
import java.util.logging.Logger;
public class TFM_Log
{
private static final Logger logger = Logger.getLogger("Minecraft");
private TFM_Log()
{
throw new AssertionError();
}
private static void log(Level level, String message, boolean raw)
{
logger.log(level, (raw ? "" : "[" + TotalFreedomMod.pluginName + "]: ") + message);
}
public static void info(String message)
{
TFM_Log.info(message, false);
}
public static void info(String message, boolean raw)
{
TFM_Log.log(Level.INFO, message, raw);
}
public static void warning(String message)
{
TFM_Log.info(message, false);
}
public static void warning(String message, boolean raw)
{
TFM_Log.log(Level.WARNING, message, raw);
}
public static void severe(String message)
{
TFM_Log.info(message, false);
}
public static void severe(String message, boolean raw)
{
TFM_Log.log(Level.SEVERE, message, raw);
}
public static void severe(Throwable ex)
{
logger.log(Level.SEVERE, null, ex);
}
}

View File

@ -3,22 +3,16 @@ package me.StevenLawson.TotalFreedomMod;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.bukkit.Server;
public class TFM_RunSystemCommand implements Runnable
{
private static final Logger log = Logger.getLogger("Minecraft");
private final String command;
private final TotalFreedomMod plugin;
private final Server server;
public TFM_RunSystemCommand(String command, TotalFreedomMod plugin)
{
this.command = command;
this.plugin = plugin;
this.server = plugin.getServer();
}
@Override
@ -40,7 +34,7 @@ public class TFM_RunSystemCommand implements Runnable
line = reader.readLine();
if (line != null)
{
log.log(Level.INFO, line);
TFM_Log.info(line);
}
}
while (line != null);
@ -52,15 +46,15 @@ public class TFM_RunSystemCommand implements Runnable
}
catch (InterruptedException ex)
{
log.log(Level.SEVERE, ex.getMessage());
TFM_Log.severe(ex.getMessage());
}
catch (IOException ex)
{
log.log(Level.SEVERE, ex.getMessage());
TFM_Log.severe(ex.getMessage());
}
catch (Throwable ex)
{
log.log(Level.SEVERE, null, ex);
TFM_Log.severe(ex);
}
}
}

View File

@ -6,8 +6,6 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
@ -16,8 +14,6 @@ public class TFM_UserList
{
private static final String USERLIST_FILENAME = "userlist.yml";
private static final Logger log = Logger.getLogger("Minecraft");
private static TFM_UserList instance = null;
private Map<String, TFM_UserListEntry> _userlist = new HashMap<String, TFM_UserListEntry>();
@ -65,7 +61,7 @@ public class TFM_UserList
}
catch (IOException ex)
{
log.log(Level.SEVERE, null, ex);
TFM_Log.severe(ex);
}
}

View File

@ -5,11 +5,10 @@ import java.net.InetSocketAddress;
import java.net.URI;
import java.util.*;
import java.util.jar.JarFile;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import java.util.zip.ZipOutputStream;
import org.apache.commons.lang.exception.ExceptionUtils;
import org.bukkit.*;
import org.bukkit.block.Block;
import org.bukkit.command.CommandSender;
@ -19,7 +18,6 @@ import org.bukkit.entity.*;
public class TFM_Util
{
private static final Logger log = Logger.getLogger("Minecraft");
private static Map<String, Integer> eject_tracker = new HashMap<String, Integer>();
public static final Map<String, EntityType> mobtypes = new HashMap<String, EntityType>();
public static final List<String> stop_commands = new ArrayList<String>();
@ -65,7 +63,7 @@ public class TFM_Util
public static void bcastMsg(String message, ChatColor color)
{
log.info(message);
TFM_Log.info(message);
for (Player p : Bukkit.getOnlinePlayers())
{
@ -75,7 +73,7 @@ public class TFM_Util
public static void bcastMsg(String message)
{
log.info(ChatColor.stripColor(message));
TFM_Log.info(message);
for (Player p : Bukkit.getOnlinePlayers())
{
@ -206,7 +204,7 @@ public class TFM_Util
File actual = new File(tfm.getDataFolder(), name);
if (!actual.exists())
{
log.info("[" + tfm.getDescription().getName() + "]: Installing default configuration file template: " + actual.getPath());
TFM_Log.info("Installing default configuration file template: " + actual.getPath());
InputStream input = null;
try
{
@ -214,14 +212,14 @@ public class TFM_Util
ZipEntry copy = file.getEntry(name);
if (copy == null)
{
log.severe("[" + tfm.getDescription().getName() + "]: Unable to read default configuration: " + actual.getPath());
TFM_Log.severe("Unable to read default configuration: " + actual.getPath());
return;
}
input = file.getInputStream(copy);
}
catch (IOException ioex)
{
log.severe("[" + tfm.getDescription().getName() + "]: Unable to read default configuration: " + actual.getPath());
TFM_Log.severe("Unable to read default configuration: " + actual.getPath());
}
if (input != null)
{
@ -238,11 +236,11 @@ public class TFM_Util
output.write(buf, 0, length);
}
log.info("[" + tfm.getDescription().getName() + "]: Default configuration file written: " + actual.getPath());
TFM_Log.info("Default configuration file written: " + actual.getPath());
}
catch (IOException ioex)
{
log.log(Level.SEVERE, "[" + tfm.getDescription().getName() + "]: Unable to write default configuration: " + actual.getPath(), ioex);
TFM_Log.severe("Unable to write default configuration: " + actual.getPath() + "\n" + ExceptionUtils.getStackTrace(ioex));
}
finally
{
@ -314,7 +312,7 @@ public class TFM_Util
}
catch (Exception ex)
{
log.severe("Exception in TFM_Util.isUserSuperadmin: " + ex.getMessage());
TFM_Log.severe(ex);
}
return false;
@ -371,7 +369,7 @@ public class TFM_Util
ip = ip.toLowerCase().trim();
if (ip.equals(match_ip))
{
log.info("New IP '" + user_ip + "' matches old IP '" + match_ip + "' via partial match, adding it to superadmin list.");
TFM_Log.info("New IP '" + user_ip + "' matches old IP '" + match_ip + "' via partial match, adding it to superadmin list.");
user_ips.add(user_ip);
config.set(user, user_ips);
break fileloop;
@ -385,7 +383,7 @@ public class TFM_Util
}
catch (IOException ex)
{
log.log(Level.SEVERE, null, ex);
TFM_Log.severe(ex);
}
}
@ -611,7 +609,7 @@ public class TFM_Util
{
}
log.info("autoEject -> name: " + p.getName() + " - player_ip: " + player_ip + " - method: " + method.toString());
TFM_Log.info("autoEject -> name: " + p.getName() + " - player_ip: " + player_ip + " - method: " + method.toString());
p.setOp(false);
p.setGameMode(GameMode.SURVIVAL);

View File

@ -10,6 +10,7 @@ import me.StevenLawson.TotalFreedomMod.Listener.TFM_BlockListener;
import me.StevenLawson.TotalFreedomMod.Listener.TFM_EntityListener;
import me.StevenLawson.TotalFreedomMod.Listener.TFM_PlayerListener;
import me.StevenLawson.TotalFreedomMod.Listener.TFM_WeatherListener;
import org.apache.commons.lang.exception.ExceptionUtils;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Server;
@ -23,7 +24,6 @@ import org.bukkit.plugin.java.JavaPlugin;
public class TotalFreedomMod extends JavaPlugin
{
private static final Logger log = Logger.getLogger("Minecraft");
private final Server server = Bukkit.getServer();
public static final long HEARTBEAT_RATE = 5L; //Seconds
@ -43,6 +43,7 @@ public class TotalFreedomMod extends JavaPlugin
public static String pluginVersion = "";
public static String buildNumber = "";
public static String buildDate = "";
public static String pluginName = "";
public static TotalFreedomMod plugin = null;
@ -50,6 +51,7 @@ public class TotalFreedomMod extends JavaPlugin
public void onEnable()
{
TotalFreedomMod.plugin = this;
TotalFreedomMod.pluginName = this.getDescription().getName();
setAppProperties();
@ -62,7 +64,7 @@ public class TotalFreedomMod extends JavaPlugin
server.getScheduler().scheduleAsyncRepeatingTask(this, new TFM_Heartbeat(this), HEARTBEAT_RATE * 20L, HEARTBEAT_RATE * 20L);
log.log(Level.INFO, "[" + getDescription().getName() + "] - Enabled! - Version: " + TotalFreedomMod.pluginVersion + "." + TotalFreedomMod.buildNumber + " by Madgeek1450 and DarthSalamon");
TFM_Log.info("Plugin Enabled - Version: " + TotalFreedomMod.pluginVersion + "." + TotalFreedomMod.buildNumber + " by Madgeek1450 and DarthSalamon");
TFM_Util.deleteFolder(new File("./_deleteme"));
@ -76,7 +78,7 @@ public class TotalFreedomMod extends JavaPlugin
public void onDisable()
{
server.getScheduler().cancelTasks(this);
log.log(Level.INFO, "[" + getDescription().getName() + "] - Disabled.");
TFM_Log.info("Plugin Disabled");
}
@Override
@ -89,19 +91,19 @@ public class TotalFreedomMod extends JavaPlugin
if (sender instanceof Player)
{
sender_p = (Player) sender;
log.info(String.format("[PLAYER_COMMAND] %s(%s): /%s %s",
TFM_Log.info(String.format("[PLAYER_COMMAND] %s(%s): /%s %s",
sender_p.getName(),
ChatColor.stripColor(sender_p.getDisplayName()),
commandLabel,
TFM_Util.implodeStringList(" ", Arrays.asList(args))));
TFM_Util.implodeStringList(" ", Arrays.asList(args))), true);
}
else
{
senderIsConsole = true;
log.info(String.format("[CONSOLE_COMMAND] %s: /%s %s",
TFM_Log.info(String.format("[CONSOLE_COMMAND] %s: /%s %s",
sender.getName(),
commandLabel,
TFM_Util.implodeStringList(" ", Arrays.asList(args))));
TFM_Util.implodeStringList(" ", Arrays.asList(args))), true);
}
TFM_Command dispatcher;
@ -113,7 +115,7 @@ public class TotalFreedomMod extends JavaPlugin
}
catch (Throwable ex)
{
log.log(Level.SEVERE, "[" + getDescription().getName() + "] Command not loaded: " + cmd.getName(), ex);
TFM_Log.severe("Command not loaded: " + cmd.getName() + "\n" + ExceptionUtils.getStackTrace(ex));
sender.sendMessage(ChatColor.RED + "Command Error: Command not loaded: " + cmd.getName());
return true;
}
@ -131,7 +133,7 @@ public class TotalFreedomMod extends JavaPlugin
}
catch (Throwable ex)
{
log.log(Level.SEVERE, "[" + getDescription().getName() + "] Command Error: " + commandLabel, ex);
TFM_Log.severe("Command Error: " + commandLabel + "\n" + ExceptionUtils.getStackTrace(ex));
sender.sendMessage(ChatColor.RED + "Unknown Command Error.");
}
@ -256,7 +258,7 @@ public class TotalFreedomMod extends JavaPlugin
}
catch (Exception ex)
{
log.log(Level.SEVERE, null, ex);
TFM_Log.severe(ex);
}
}
}

View File

@ -2,7 +2,7 @@ name: TotalFreedomMod
main: me.StevenLawson.TotalFreedomMod.TotalFreedomMod
version: 2.7
description: Plugin for the Total Freedom server.
author: StevenLawson / Madgeek1450
authors: [StevenLawson / Madgeek1450, JeromSar / DarthSalamon]
commands:
cage:
description: Superadmin command - Place a cage around someone.
@ -189,4 +189,4 @@ commands:
# usage: /<command>
ziptool:
description: Owner command - Zip and unzip files.
usage: /<command> <zip <directory>> | <unzip <file>>
usage: /<command> <zip <directory>> | <unzip <file>>