Add option to strip color codes from server.log file

This commit is contained in:
Travis Watkins 2012-05-15 20:18:35 -05:00
parent e91169ebad
commit 4c8f6f2caa
3 changed files with 21 additions and 3 deletions

View File

@ -10,8 +10,14 @@ import java.util.logging.LogRecord;
final class ConsoleLogFormatter extends Formatter {
private SimpleDateFormat a = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
// CraftBukkit start - add color stripping, change constructor to take it
private java.util.regex.Pattern pattern = java.util.regex.Pattern.compile("\\x1B\\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]");
private boolean strip = false;
ConsoleLogFormatter() {}
ConsoleLogFormatter(boolean strip) {
this.strip = strip;
}
// CraftBukkit end
public String format(LogRecord logrecord) {
StringBuilder stringbuilder = new StringBuilder();
@ -46,6 +52,12 @@ final class ConsoleLogFormatter extends Formatter {
stringbuilder.append(stringwriter.toString());
}
return stringbuilder.toString();
// CraftBukkit start - handle stripping color
if (this.strip) {
return this.pattern.matcher(stringbuilder.toString()).replaceAll("");
} else {
return stringbuilder.toString();
}
// CraftBukkit end
}
}

View File

@ -22,7 +22,7 @@ public class ConsoleLogManager {
// CraftBukkit - change of method signature!
public static void init(MinecraftServer server) {
ConsoleLogFormatter consolelogformatter = new ConsoleLogFormatter();
ConsoleLogFormatter consolelogformatter = new ConsoleLogFormatter(server.options.has("log-strip-color")); // CraftBukkit - pass strip color option
a.setUseParentHandlers(false);
// CraftBukkit start

View File

@ -87,6 +87,12 @@ public class Main {
.defaultsTo(true)
.describedAs("Log append");
acceptsAll(asList("log-strip-color"), "Whether to strip color codes from log file")
.withRequiredArg()
.ofType(Boolean.class)
.defaultsTo(false)
.describedAs("Log stripping");
acceptsAll(asList("b", "bukkit-settings"), "File for bukkit settings")
.withRequiredArg()
.ofType(File.class)