mirror of
https://github.com/NoCheatPlus/NoCheatPlus.git
synced 2024-11-08 03:29:36 +01:00
Log time AND date to logfile
This commit is contained in:
parent
b656644b29
commit
5725209bc6
37
src/cc/co/evenprime/bukkit/nocheat/LogFileFormatter.java
Normal file
37
src/cc/co/evenprime/bukkit/nocheat/LogFileFormatter.java
Normal 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();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -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) {
|
||||||
|
Loading…
Reference in New Issue
Block a user