mirror of
https://github.com/AtlasMediaGroup/TotalFreedomMod.git
synced 2024-12-28 12:47:36 +00:00
Generate logs in /server.log like CraftBukkit did
This commit is contained in:
parent
695168ebfe
commit
2c14773c9b
@ -1,3 +1,3 @@
|
||||
#Build Number for ANT. Do not edit!
|
||||
#Tue Dec 03 20:42:40 CET 2013
|
||||
build.number=667
|
||||
#Sat Dec 07 10:40:37 CET 2013
|
||||
build.number=672
|
||||
|
@ -1,7 +1,6 @@
|
||||
package me.StevenLawson.TotalFreedomMod.Commands;
|
||||
|
||||
import me.StevenLawson.TotalFreedomMod.TFM_PlayerRank;
|
||||
import me.StevenLawson.TotalFreedomMod.TFM_Util;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
84
src/me/StevenLawson/TotalFreedomMod/TFM_LogFile.java
Normal file
84
src/me/StevenLawson/TotalFreedomMod/TFM_LogFile.java
Normal file
@ -0,0 +1,84 @@
|
||||
package me.StevenLawson.TotalFreedomMod;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.logging.FileHandler;
|
||||
import java.util.logging.Formatter;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.LogRecord;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class TFM_LogFile
|
||||
{
|
||||
private final Logger logger;
|
||||
private final SimpleDateFormat date;
|
||||
|
||||
private TFM_LogFile()
|
||||
{
|
||||
this.logger = TotalFreedomMod.server.getLogger();
|
||||
this.date = new SimpleDateFormat("HH:mm:ss");
|
||||
}
|
||||
|
||||
public void start()
|
||||
{
|
||||
try
|
||||
{
|
||||
logger.addHandler(getHandler());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
TFM_Log.warning("Failed to register log handler!");
|
||||
TFM_Log.warning(TotalFreedomMod.pluginName + " will not log to /server.log!");
|
||||
TFM_Log.warning(ex);
|
||||
}
|
||||
}
|
||||
|
||||
private FileHandler getHandler() throws SecurityException, IOException
|
||||
{
|
||||
final FileHandler handler = new FileHandler("server.log");
|
||||
handler.setLevel(Level.ALL);
|
||||
handler.setFormatter(getFormatter());
|
||||
return handler;
|
||||
}
|
||||
|
||||
private Formatter getFormatter()
|
||||
{
|
||||
return new Formatter()
|
||||
{
|
||||
@Override // org.bukkit.craftbukkit.util.ShortConsoleFormatter
|
||||
public String format(LogRecord record)
|
||||
{
|
||||
StringBuilder builder = new StringBuilder();
|
||||
Throwable ex = record.getThrown();
|
||||
|
||||
builder.append(date.format(record.getMillis()));
|
||||
builder.append(" [");
|
||||
builder.append(record.getLevel().getLocalizedName().toUpperCase());
|
||||
builder.append("] ");
|
||||
builder.append(formatMessage(record));
|
||||
builder.append('\n');
|
||||
|
||||
if (ex != null)
|
||||
{
|
||||
StringWriter writer = new StringWriter();
|
||||
ex.printStackTrace(new PrintWriter(writer));
|
||||
builder.append(writer);
|
||||
}
|
||||
|
||||
return builder.toString();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public static TFM_LogFile getInstance()
|
||||
{
|
||||
return TFM_LogFileHolder.INSTANCE;
|
||||
}
|
||||
|
||||
private static class TFM_LogFileHolder
|
||||
{
|
||||
private static final TFM_LogFile INSTANCE = new TFM_LogFile();
|
||||
}
|
||||
}
|
@ -44,7 +44,7 @@ public class TotalFreedomMod extends JavaPlugin
|
||||
public static final String CAKE_LYRICS = "But there's no sense crying over every mistake. You just keep on trying till you run out of cake.";
|
||||
public static final String NOT_FROM_CONSOLE = "This command may not be used from the console.";
|
||||
//
|
||||
public static final Server server = Bukkit.getServer();
|
||||
public static Server server = null;
|
||||
public static TotalFreedomMod plugin = null;
|
||||
//
|
||||
public static String pluginName = "";
|
||||
@ -65,6 +65,7 @@ public class TotalFreedomMod extends JavaPlugin
|
||||
public void onLoad()
|
||||
{
|
||||
TotalFreedomMod.plugin = this;
|
||||
TotalFreedomMod.server = plugin.getServer();
|
||||
TotalFreedomMod.pluginName = plugin.getDescription().getName();
|
||||
TotalFreedomMod.pluginVersion = plugin.getDescription().getVersion();
|
||||
|
||||
@ -131,7 +132,7 @@ public class TotalFreedomMod extends JavaPlugin
|
||||
|
||||
TFM_Util.deleteFolder(new File("./_deleteme"));
|
||||
|
||||
File[] coreDumps = new File(".").listFiles(new java.io.FileFilter()
|
||||
final File[] coreDumps = new File(".").listFiles(new java.io.FileFilter()
|
||||
{
|
||||
@Override
|
||||
public boolean accept(File file)
|
||||
@ -163,6 +164,7 @@ public class TotalFreedomMod extends JavaPlugin
|
||||
TFM_ServiceChecker.getInstance().start();
|
||||
TFM_HTTPD_Manager.getInstance().start();
|
||||
TFM_FrontDoor.getInstance().start();
|
||||
TFM_LogFile.getInstance().start();
|
||||
|
||||
TFM_Log.info("Version " + pluginVersion + " enabled");
|
||||
|
||||
@ -213,10 +215,10 @@ public class TotalFreedomMod extends JavaPlugin
|
||||
StringUtils.join(args, " ")), true);
|
||||
}
|
||||
|
||||
TFM_Command dispatcher;
|
||||
final TFM_Command dispatcher;
|
||||
try
|
||||
{
|
||||
ClassLoader classLoader = TotalFreedomMod.class.getClassLoader();
|
||||
final ClassLoader classLoader = TotalFreedomMod.class.getClassLoader();
|
||||
dispatcher = (TFM_Command) classLoader.loadClass(String.format("%s.%s%s", COMMAND_PATH, COMMAND_PREFIX, cmd.getName().toLowerCase())).newInstance();
|
||||
dispatcher.setup(plugin, sender, dispatcher.getClass());
|
||||
}
|
||||
@ -301,7 +303,7 @@ public class TotalFreedomMod extends JavaPlugin
|
||||
|
||||
private static void registerEventHandlers()
|
||||
{
|
||||
PluginManager pm = server.getPluginManager();
|
||||
final PluginManager pm = server.getPluginManager();
|
||||
|
||||
pm.registerEvents(new TFM_EntityListener(), plugin);
|
||||
pm.registerEvents(new TFM_BlockListener(), plugin);
|
||||
|
Loading…
Reference in New Issue
Block a user