From 10893fea38179942f6028be150fba3b823a9b1d1 Mon Sep 17 00:00:00 2001 From: Minecrell Date: Mon, 18 Sep 2017 12:07:47 +0200 Subject: [PATCH] Use Log4j IOStreams to redirect System.out/err to logger Log4j2 provides an optimized implementation of PrintStream that redirects its output to a logger. Use it instead of a custom implementation for minor performance improvements and some fixes. With the old implementation, each call to System.print() results in a separate line, even though it should not result in a line break. Log4j's implementation handles it correctly. --- ...ams-to-redirect-System.out-err-to-lo.patch | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 Spigot-Server-Patches/0238-Use-Log4j-IOStreams-to-redirect-System.out-err-to-lo.patch diff --git a/Spigot-Server-Patches/0238-Use-Log4j-IOStreams-to-redirect-System.out-err-to-lo.patch b/Spigot-Server-Patches/0238-Use-Log4j-IOStreams-to-redirect-System.out-err-to-lo.patch new file mode 100644 index 0000000000..b504df2b29 --- /dev/null +++ b/Spigot-Server-Patches/0238-Use-Log4j-IOStreams-to-redirect-System.out-err-to-lo.patch @@ -0,0 +1,51 @@ +From a7ced92f0d09b6e25e5c66dc24db2da45f3341f7 Mon Sep 17 00:00:00 2001 +From: Minecrell +Date: Mon, 18 Sep 2017 12:00:03 +0200 +Subject: [PATCH] Use Log4j IOStreams to redirect System.out/err to logger + +Log4j2 provides an optimized implementation of PrintStream that +redirects its output to a logger. Use it instead of a custom +implementation for minor performance improvements and some fixes. + +With the old implementation, each call to System.print() +results in a separate line, even though it should not result in +a line break. Log4j's implementation handles it correctly. + +diff --git a/pom.xml b/pom.xml +index 98972114d..aff997468 100644 +--- a/pom.xml ++++ b/pom.xml +@@ -97,6 +97,13 @@ + runtime + + ++ ++ ++ org.apache.logging.log4j ++ log4j-iostreams ++ 2.8.1 ++ ++ + + + junit +diff --git a/src/main/java/net/minecraft/server/DedicatedServer.java b/src/main/java/net/minecraft/server/DedicatedServer.java +index b3f1aa999..854455711 100644 +--- a/src/main/java/net/minecraft/server/DedicatedServer.java ++++ b/src/main/java/net/minecraft/server/DedicatedServer.java +@@ -129,8 +129,10 @@ public class DedicatedServer extends MinecraftServer implements IMinecraftServer + */ + // Paper end + +- System.setOut(new PrintStream(new LoggerOutputStream(logger, Level.INFO), true)); +- System.setErr(new PrintStream(new LoggerOutputStream(logger, Level.WARN), true)); ++ // Paper start - Use Log4j IOStreams ++ System.setOut(org.apache.logging.log4j.io.IoBuilder.forLogger(logger).setLevel(Level.INFO).buildPrintStream()); ++ System.setErr(org.apache.logging.log4j.io.IoBuilder.forLogger(logger).setLevel(Level.WARN).buildPrintStream()); ++ // Paper end + // CraftBukkit end + + thread.setDaemon(true); +-- +2.14.1 +