diff --git a/src/main/java/net/minecraft/server/ConsoleLogFormatter.java b/src/main/java/net/minecraft/server/ConsoleLogFormatter.java index e2f8793dcc..2ed2a5e7ec 100644 --- a/src/main/java/net/minecraft/server/ConsoleLogFormatter.java +++ b/src/main/java/net/minecraft/server/ConsoleLogFormatter.java @@ -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 } } diff --git a/src/main/java/net/minecraft/server/ConsoleLogManager.java b/src/main/java/net/minecraft/server/ConsoleLogManager.java index 91388f93e1..b2280081ed 100644 --- a/src/main/java/net/minecraft/server/ConsoleLogManager.java +++ b/src/main/java/net/minecraft/server/ConsoleLogManager.java @@ -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 diff --git a/src/main/java/org/bukkit/craftbukkit/Main.java b/src/main/java/org/bukkit/craftbukkit/Main.java index c5bfa3a299..b6e8d341ed 100644 --- a/src/main/java/org/bukkit/craftbukkit/Main.java +++ b/src/main/java/org/bukkit/craftbukkit/Main.java @@ -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)