From 0000000000000000000000000000000000000000 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 aeaceac771644ece5365d07be77f4481ced2fe13..25e327c38cc3aa1f9ad9275faba481bdb4240e25 100644 --- a/pom.xml +++ b/pom.xml @@ -66,6 +66,11 @@ 2.8.1 runtime + + org.apache.logging.log4j + log4j-iostreams + 2.8.1 + org.ow2.asm asm diff --git a/src/main/java/net/minecraft/server/DedicatedServer.java b/src/main/java/net/minecraft/server/DedicatedServer.java index d34f772fae3543cec6a130831b1f3eaa67934944..ec257ba31f012d3d3576bbff41326df13ede6776 100644 --- a/src/main/java/net/minecraft/server/DedicatedServer.java +++ b/src/main/java/net/minecraft/server/DedicatedServer.java @@ -155,8 +155,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);