3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-12-20 21:40:06 +01:00

Add option to strip color codes from server.log file

Dieser Commit ist enthalten in:
Travis Watkins 2012-05-15 20:18:35 -05:00
Ursprung e91169ebad
Commit 4c8f6f2caa
3 geänderte Dateien mit 21 neuen und 3 gelöschten Zeilen

Datei anzeigen

@ -10,8 +10,14 @@ import java.util.logging.LogRecord;
final class ConsoleLogFormatter extends Formatter { final class ConsoleLogFormatter extends Formatter {
private SimpleDateFormat a = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); 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) { public String format(LogRecord logrecord) {
StringBuilder stringbuilder = new StringBuilder(); StringBuilder stringbuilder = new StringBuilder();
@ -46,6 +52,12 @@ final class ConsoleLogFormatter extends Formatter {
stringbuilder.append(stringwriter.toString()); stringbuilder.append(stringwriter.toString());
} }
// CraftBukkit start - handle stripping color
if (this.strip) {
return this.pattern.matcher(stringbuilder.toString()).replaceAll("");
} else {
return stringbuilder.toString(); return stringbuilder.toString();
} }
// CraftBukkit end
}
} }

Datei anzeigen

@ -22,7 +22,7 @@ public class ConsoleLogManager {
// CraftBukkit - change of method signature! // CraftBukkit - change of method signature!
public static void init(MinecraftServer server) { 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); a.setUseParentHandlers(false);
// CraftBukkit start // CraftBukkit start

Datei anzeigen

@ -87,6 +87,12 @@ public class Main {
.defaultsTo(true) .defaultsTo(true)
.describedAs("Log append"); .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") acceptsAll(asList("b", "bukkit-settings"), "File for bukkit settings")
.withRequiredArg() .withRequiredArg()
.ofType(File.class) .ofType(File.class)