From 68fde1e795b64eb5baeb21084d9cd8064f58debb Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Sat, 29 Dec 2018 13:30:50 -0500 Subject: [PATCH] Adapt System.(out|err) to log4j. --- proxy/build.gradle | 4 ++++ .../com/velocitypowered/proxy/VelocityServer.java | 1 + .../proxy/console/VelocityConsole.java | 12 ++++++++++++ 3 files changed, 17 insertions(+) diff --git a/proxy/build.gradle b/proxy/build.gradle index 35b3bd7f8..9d0621095 100644 --- a/proxy/build.gradle +++ b/proxy/build.gradle @@ -38,6 +38,7 @@ dependencies { compile "org.apache.logging.log4j:log4j-api:${log4jVersion}" compile "org.apache.logging.log4j:log4j-core:${log4jVersion}" compile "org.apache.logging.log4j:log4j-slf4j-impl:${log4jVersion}" + compile "org.apache.logging.log4j:log4j-iostreams:${log4jVersion}" compile 'net.sf.jopt-simple:jopt-simple:5.0.4' // command-line options compile 'net.minecrell:terminalconsoleappender:1.1.1' @@ -63,11 +64,14 @@ shadowJar { exclude 'it/unimi/dsi/fastutil/ints/IntAVL*' exclude 'it/unimi/dsi/fastutil/ints/IntArray*' exclude 'it/unimi/dsi/fastutil/ints/IntBi*' + exclude 'it/unimi/dsi/fastutil/ints/IntLinked*' exclude 'it/unimi/dsi/fastutil/ints/IntList*' exclude 'it/unimi/dsi/fastutil/ints/IntOpen*' exclude 'it/unimi/dsi/fastutil/ints/IntRB*' exclude 'it/unimi/dsi/fastutil/ints/IntSet*' exclude 'it/unimi/dsi/fastutil/ints/IntSorted*' + exclude 'it/unimi/dsi/fastutil/ints/*Priority*' + exclude 'it/unimi/dsi/fastutil/ints/*BigList*' exclude 'it/unimi/dsi/fastutil/io/**' exclude 'it/unimi/dsi/fastutil/longs/**' exclude 'it/unimi/dsi/fastutil/objects/*ObjectArray*' diff --git a/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java b/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java index 0b49cf1a4..721541bae 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java @@ -146,6 +146,7 @@ public class VelocityServer implements ProxyServer { "console", "cm", "configuration"}) void start() { logger.info("Booting up {} {}...", getVersion().getName(), getVersion().getVersion()); + console.setupStreams(); serverKeyPair = EncryptionUtils.createRsaKeyPair(1024); diff --git a/proxy/src/main/java/com/velocitypowered/proxy/console/VelocityConsole.java b/proxy/src/main/java/com/velocitypowered/proxy/console/VelocityConsole.java index 79fe49d10..49f0348cf 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/console/VelocityConsole.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/console/VelocityConsole.java @@ -5,14 +5,17 @@ import com.velocitypowered.api.permission.PermissionFunction; import com.velocitypowered.api.permission.Tristate; import com.velocitypowered.api.proxy.ConsoleCommandSource; import com.velocitypowered.proxy.VelocityServer; +import java.io.PrintWriter; import java.util.List; import net.kyori.text.Component; import net.kyori.text.TextComponent; import net.kyori.text.format.TextColor; import net.kyori.text.serializer.ComponentSerializers; import net.minecrell.terminalconsole.SimpleTerminalConsole; +import org.apache.logging.log4j.Level; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.io.IoBuilder; import org.checkerframework.checker.nullness.qual.NonNull; import org.jline.reader.Candidate; import org.jline.reader.LineReader; @@ -39,6 +42,15 @@ public final class VelocityConsole extends SimpleTerminalConsole implements Cons return this.permissionFunction.getPermissionValue(permission); } + public void setupStreams() { + System.setOut(IoBuilder.forLogger(logger) + .setLevel(Level.INFO) + .buildPrintStream()); + System.setErr(IoBuilder.forLogger(logger) + .setLevel(Level.ERROR) + .buildPrintStream()); + } + public void setupPermissions() { PermissionsSetupEvent event = new PermissionsSetupEvent(this, s -> PermissionFunction.ALWAYS_TRUE);