From 5725209bc65d474a14d5154fe9c7a8b947d49962 Mon Sep 17 00:00:00 2001 From: Evenprime Date: Sat, 14 May 2011 18:08:43 +0200 Subject: [PATCH] Log time AND date to logfile --- .../bukkit/nocheat/LogFileFormatter.java | 37 +++++++++++++++++++ .../bukkit/nocheat/NoCheatConfiguration.java | 2 +- 2 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 src/cc/co/evenprime/bukkit/nocheat/LogFileFormatter.java diff --git a/src/cc/co/evenprime/bukkit/nocheat/LogFileFormatter.java b/src/cc/co/evenprime/bukkit/nocheat/LogFileFormatter.java new file mode 100644 index 00000000..1b0d078d --- /dev/null +++ b/src/cc/co/evenprime/bukkit/nocheat/LogFileFormatter.java @@ -0,0 +1,37 @@ +package cc.co.evenprime.bukkit.nocheat; + +import java.io.PrintWriter; +import java.io.StringWriter; +import java.text.SimpleDateFormat; +import java.util.logging.Formatter; +import java.util.logging.LogRecord; + +public class LogFileFormatter extends Formatter { + private final SimpleDateFormat date; + + public LogFileFormatter() { + date = new SimpleDateFormat("yy.MM.dd HH:mm:ss"); + } + + @Override + 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(record.getMessage()); + builder.append('\n'); + + if (ex != null) { + StringWriter writer = new StringWriter(); + ex.printStackTrace(new PrintWriter(writer)); + builder.append(writer); + } + + return builder.toString(); + } + +} \ No newline at end of file diff --git a/src/cc/co/evenprime/bukkit/nocheat/NoCheatConfiguration.java b/src/cc/co/evenprime/bukkit/nocheat/NoCheatConfiguration.java index ac4371f1..c4c0666a 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/NoCheatConfiguration.java +++ b/src/cc/co/evenprime/bukkit/nocheat/NoCheatConfiguration.java @@ -81,7 +81,7 @@ public class NoCheatConfiguration { try { fh = new FileHandler(fileName, true); fh.setLevel(fileLevel); - fh.setFormatter(Logger.getLogger("Minecraft").getHandlers()[0].getFormatter()); + fh.setFormatter(new LogFileFormatter()); logger.addHandler(fh); } catch (Exception e) {