2012-05-16 02:58:46 +02:00
|
|
|
package net.minecraft.server;
|
|
|
|
|
|
|
|
import java.io.PrintWriter;
|
|
|
|
import java.io.StringWriter;
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
|
import java.util.logging.Formatter;
|
|
|
|
import java.util.logging.Level;
|
|
|
|
import java.util.logging.LogRecord;
|
|
|
|
|
2012-07-22 08:18:00 +02:00
|
|
|
import java.util.regex.Pattern; // CraftBukkit
|
|
|
|
|
2012-05-16 02:58:46 +02:00
|
|
|
final class ConsoleLogFormatter extends Formatter {
|
|
|
|
|
|
|
|
private SimpleDateFormat a = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
2012-05-16 03:18:35 +02:00
|
|
|
// CraftBukkit start - add color stripping, change constructor to take it
|
2012-07-22 08:18:00 +02:00
|
|
|
private Pattern pattern = Pattern.compile("\\x1B\\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]");
|
2012-05-16 03:18:35 +02:00
|
|
|
private boolean strip = false;
|
2012-05-16 02:58:46 +02:00
|
|
|
|
2012-05-16 03:18:35 +02:00
|
|
|
ConsoleLogFormatter(boolean strip) {
|
|
|
|
this.strip = strip;
|
|
|
|
}
|
|
|
|
// CraftBukkit end
|
2012-05-16 02:58:46 +02:00
|
|
|
|
|
|
|
public String format(LogRecord logrecord) {
|
|
|
|
StringBuilder stringbuilder = new StringBuilder();
|
|
|
|
|
|
|
|
stringbuilder.append(this.a.format(Long.valueOf(logrecord.getMillis())));
|
|
|
|
Level level = logrecord.getLevel();
|
|
|
|
|
|
|
|
if (level == Level.FINEST) {
|
|
|
|
stringbuilder.append(" [FINEST] ");
|
|
|
|
} else if (level == Level.FINER) {
|
|
|
|
stringbuilder.append(" [FINER] ");
|
|
|
|
} else if (level == Level.FINE) {
|
|
|
|
stringbuilder.append(" [FINE] ");
|
|
|
|
} else if (level == Level.INFO) {
|
|
|
|
stringbuilder.append(" [INFO] ");
|
|
|
|
} else if (level == Level.WARNING) {
|
|
|
|
stringbuilder.append(" [WARNING] ");
|
|
|
|
} else if (level == Level.SEVERE) {
|
|
|
|
stringbuilder.append(" [SEVERE] ");
|
2012-08-12 01:29:50 +02:00
|
|
|
} else { // CraftBukkit
|
2012-07-29 09:33:13 +02:00
|
|
|
stringbuilder.append(" [").append(level.getLocalizedName()).append("] ");
|
2012-05-16 02:58:46 +02:00
|
|
|
}
|
|
|
|
|
2012-08-12 01:29:50 +02:00
|
|
|
stringbuilder.append(formatMessage(logrecord)); // CraftBukkit
|
2012-05-16 02:58:46 +02:00
|
|
|
stringbuilder.append('\n');
|
|
|
|
Throwable throwable = logrecord.getThrown();
|
|
|
|
|
|
|
|
if (throwable != null) {
|
|
|
|
StringWriter stringwriter = new StringWriter();
|
|
|
|
|
|
|
|
throwable.printStackTrace(new PrintWriter(stringwriter));
|
|
|
|
stringbuilder.append(stringwriter.toString());
|
|
|
|
}
|
|
|
|
|
2012-05-16 03:18:35 +02:00
|
|
|
// CraftBukkit start - handle stripping color
|
|
|
|
if (this.strip) {
|
|
|
|
return this.pattern.matcher(stringbuilder.toString()).replaceAll("");
|
|
|
|
} else {
|
|
|
|
return stringbuilder.toString();
|
|
|
|
}
|
|
|
|
// CraftBukkit end
|
2012-05-16 02:58:46 +02:00
|
|
|
}
|
|
|
|
}
|