Log time AND date to logfile

This commit is contained in:
Evenprime 2011-05-14 18:08:43 +02:00
parent b656644b29
commit 5725209bc6
2 changed files with 38 additions and 1 deletions

View File

@ -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();
}
}

View File

@ -81,7 +81,7 @@ public class NoCheatConfiguration {
try { try {
fh = new FileHandler(fileName, true); fh = new FileHandler(fileName, true);
fh.setLevel(fileLevel); fh.setLevel(fileLevel);
fh.setFormatter(Logger.getLogger("Minecraft").getHandlers()[0].getFormatter()); fh.setFormatter(new LogFileFormatter());
logger.addHandler(fh); logger.addHandler(fh);
} catch (Exception e) { } catch (Exception e) {