Skip to content

Instantly share code, notes, and snippets.

@gigaherz
Created August 4, 2019 23:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gigaherz/89a5f6abb8725fc84d3e15a86ccef6ec to your computer and use it in GitHub Desktop.
Save gigaherz/89a5f6abb8725fc84d3e15a86ccef6ec to your computer and use it in GitHub Desktop.
From 0e33e41ca6e711812d0a38fd20703bce74792545 Mon Sep 17 00:00:00 2001
From: David Quintana <gigaherz@gmail.com>
Date: Mon, 5 Aug 2019 01:40:44 +0200
Subject: [PATCH] Netty logging
---
src/fmllauncher/resources/log4j2.xml | 1 +
.../logging/ForgeNettyLogger.java | 504 ++++++++++++++++++
.../minecraftforge/userdev/LaunchTesting.java | 4 +
3 files changed, 509 insertions(+)
create mode 100644 src/main/java/net/minecraftforge/logging/ForgeNettyLogger.java
diff --git a/src/fmllauncher/resources/log4j2.xml b/src/fmllauncher/resources/log4j2.xml
index 29eb491b0..e816f8a04 100644
--- a/src/fmllauncher/resources/log4j2.xml
+++ b/src/fmllauncher/resources/log4j2.xml
@@ -57,6 +57,7 @@
<Logger level="${sys:forge.logging.mojang.level:-info}" name="com.mojang"/>
<Logger level="${sys:forge.logging.mojang.level:-info}" name="net.minecraft"/>
<Logger level="${sys:forge.logging.classtransformer.level:-info}" name="cpw.mods.modlauncher.ClassTransformer"/>
+ <Logger level="trace" name="io.netty"/>
<Root level="all">
<AppenderRef ref="Console" level="${sys:forge.logging.console.level:-info}"/>
<AppenderRef ref="ServerGuiConsole" level="${sys:forge.logging.console.level:-info}"/>
diff --git a/src/main/java/net/minecraftforge/logging/ForgeNettyLogger.java b/src/main/java/net/minecraftforge/logging/ForgeNettyLogger.java
new file mode 100644
index 000000000..fe586956a
--- /dev/null
+++ b/src/main/java/net/minecraftforge/logging/ForgeNettyLogger.java
@@ -0,0 +1,504 @@
+package net.minecraftforge.logging;
+
+import io.netty.util.internal.logging.AbstractInternalLogger;
+import io.netty.util.internal.logging.InternalLogger;
+import io.netty.util.internal.logging.InternalLoggerFactory;
+import org.apache.logging.log4j.Marker;
+import org.apache.logging.log4j.MarkerManager;
+
+public class ForgeNettyLogger extends AbstractInternalLogger
+{
+ public static class Factory extends InternalLoggerFactory
+ {
+ public static final InternalLoggerFactory INSTANCE = new Factory();
+
+ private Factory() {
+ }
+
+ @Override
+ public InternalLogger newInstance(String name) {
+ return new ForgeNettyLogger(org.apache.logging.log4j.LogManager.getLogger(name));
+ }
+ }
+
+ final transient org.apache.logging.log4j.Logger logger;
+
+ /**
+ * Following the pattern discussed in pages 162 through 168 of "The complete
+ * log4j manual".
+ */
+ static final Marker FQCN = MarkerManager.getMarker(ForgeNettyLogger.class.getName());
+
+ ForgeNettyLogger(org.apache.logging.log4j.Logger logger) {
+ super(logger.getName());
+ this.logger = logger;
+ }
+
+ /**
+ * Is this logger instance enabled for the TRACE level?
+ *
+ * @return True if this Logger is enabled for level TRACE, false otherwise.
+ */
+ @Override
+ public boolean isTraceEnabled() {
+ return logger.isTraceEnabled();
+ }
+
+ /**
+ * Log a message object at level TRACE.
+ *
+ * @param msg
+ * - the message object to be logged
+ */
+ @Override
+ public void trace(String msg) {
+ logger.trace(FQCN, msg);
+ }
+
+ /**
+ * Log a message at level TRACE according to the specified format and
+ * argument.
+ *
+ * <p>
+ * This form avoids superfluous object creation when the logger is disabled
+ * for level TRACE.
+ * </p>
+ *
+ * @param format
+ * the format string
+ * @param arg
+ * the argument
+ */
+ @Override
+ public void trace(String format, Object arg) {
+ logger.trace(FQCN, format, arg);
+ }
+
+ /**
+ * Log a message at level TRACE according to the specified format and
+ * arguments.
+ *
+ * <p>
+ * This form avoids superfluous object creation when the logger is disabled
+ * for the TRACE level.
+ * </p>
+ *
+ * @param format
+ * the format string
+ * @param argA
+ * the first argument
+ * @param argB
+ * the second argument
+ */
+ @Override
+ public void trace(String format, Object argA, Object argB) {
+ logger.trace(FQCN, format, argA, argB);
+ }
+
+ /**
+ * Log a message at level TRACE according to the specified format and
+ * arguments.
+ *
+ * <p>
+ * This form avoids superfluous object creation when the logger is disabled
+ * for the TRACE level.
+ * </p>
+ *
+ * @param format
+ * the format string
+ * @param arguments
+ * an array of arguments
+ */
+ @Override
+ public void trace(String format, Object... arguments) {
+ logger.trace(FQCN, format, arguments);
+ }
+
+ /**
+ * Log an exception (throwable) at level TRACE with an accompanying message.
+ *
+ * @param msg
+ * the message accompanying the exception
+ * @param t
+ * the exception (throwable) to log
+ */
+ @Override
+ public void trace(String msg, Throwable t) {
+ logger.trace(FQCN, msg, t);
+ }
+
+ /**
+ * Is this logger instance enabled for the DEBUG level?
+ *
+ * @return True if this Logger is enabled for level DEBUG, false otherwise.
+ */
+ @Override
+ public boolean isDebugEnabled() {
+ return logger.isDebugEnabled();
+ }
+
+ /**
+ * Log a message object at level DEBUG.
+ *
+ * @param msg
+ * - the message object to be logged
+ */
+ @Override
+ public void debug(String msg) {
+ logger.debug(FQCN, msg);
+ }
+
+ /**
+ * Log a message at level DEBUG according to the specified format and
+ * argument.
+ *
+ * <p>
+ * This form avoids superfluous object creation when the logger is disabled
+ * for level DEBUG.
+ * </p>
+ *
+ * @param format
+ * the format string
+ * @param arg
+ * the argument
+ */
+ @Override
+ public void debug(String format, Object arg) {
+ logger.debug(FQCN, format, arg);
+ }
+
+ /**
+ * Log a message at level DEBUG according to the specified format and
+ * arguments.
+ *
+ * <p>
+ * This form avoids superfluous object creation when the logger is disabled
+ * for the DEBUG level.
+ * </p>
+ *
+ * @param format
+ * the format string
+ * @param argA
+ * the first argument
+ * @param argB
+ * the second argument
+ */
+ @Override
+ public void debug(String format, Object argA, Object argB) {
+ logger.debug(FQCN, format, argA, argB);
+ }
+
+ /**
+ * Log a message at level DEBUG according to the specified format and
+ * arguments.
+ *
+ * <p>
+ * This form avoids superfluous object creation when the logger is disabled
+ * for the DEBUG level.
+ * </p>
+ *
+ * @param format
+ * the format string
+ * @param arguments an array of arguments
+ */
+ @Override
+ public void debug(String format, Object... arguments) {
+ logger.debug(FQCN, format, arguments);
+ }
+
+ /**
+ * Log an exception (throwable) at level DEBUG with an accompanying message.
+ *
+ * @param msg
+ * the message accompanying the exception
+ * @param t
+ * the exception (throwable) to log
+ */
+ @Override
+ public void debug(String msg, Throwable t) {
+ logger.debug(FQCN, msg, t);
+ }
+
+ /**
+ * Is this logger instance enabled for the INFO level?
+ *
+ * @return True if this Logger is enabled for the INFO level, false otherwise.
+ */
+ @Override
+ public boolean isInfoEnabled() {
+ return logger.isInfoEnabled();
+ }
+
+ /**
+ * Log a message object at the INFO level.
+ *
+ * @param msg
+ * - the message object to be logged
+ */
+ @Override
+ public void info(String msg) {
+ logger.info(FQCN, msg);
+ }
+
+ /**
+ * Log a message at level INFO according to the specified format and argument.
+ *
+ * <p>
+ * This form avoids superfluous object creation when the logger is disabled
+ * for the INFO level.
+ * </p>
+ *
+ * @param format
+ * the format string
+ * @param arg
+ * the argument
+ */
+ @Override
+ public void info(String format, Object arg) {
+ logger.info(FQCN, format, arg);
+ }
+
+ /**
+ * Log a message at the INFO level according to the specified format and
+ * arguments.
+ *
+ * <p>
+ * This form avoids superfluous object creation when the logger is disabled
+ * for the INFO level.
+ * </p>
+ *
+ * @param format
+ * the format string
+ * @param argA
+ * the first argument
+ * @param argB
+ * the second argument
+ */
+ @Override
+ public void info(String format, Object argA, Object argB) {
+ logger.info(FQCN, format, argA, argB);
+ }
+
+ /**
+ * Log a message at level INFO according to the specified format and
+ * arguments.
+ *
+ * <p>
+ * This form avoids superfluous object creation when the logger is disabled
+ * for the INFO level.
+ * </p>
+ *
+ * @param format
+ * the format string
+ * @param argArray
+ * an array of arguments
+ */
+ @Override
+ public void info(String format, Object... argArray) {
+ logger.info(FQCN, format, argArray);
+ }
+
+ /**
+ * Log an exception (throwable) at the INFO level with an accompanying
+ * message.
+ *
+ * @param msg
+ * the message accompanying the exception
+ * @param t
+ * the exception (throwable) to log
+ */
+ @Override
+ public void info(String msg, Throwable t) {
+ logger.info(FQCN, msg, t);
+ }
+
+ /**
+ * Is this logger instance enabled for the WARN level?
+ *
+ * @return True if this Logger is enabled for the WARN level, false otherwise.
+ */
+ @Override
+ public boolean isWarnEnabled() {
+ return logger.isWarnEnabled();
+ }
+
+ /**
+ * Log a message object at the WARN level.
+ *
+ * @param msg
+ * - the message object to be logged
+ */
+ @Override
+ public void warn(String msg) {
+ logger.warn(FQCN, msg);
+ }
+
+ /**
+ * Log a message at the WARN level according to the specified format and
+ * argument.
+ *
+ * <p>
+ * This form avoids superfluous object creation when the logger is disabled
+ * for the WARN level.
+ * </p>
+ *
+ * @param format
+ * the format string
+ * @param arg
+ * the argument
+ */
+ @Override
+ public void warn(String format, Object arg) {
+ logger.warn(FQCN, format, arg);
+ }
+
+ /**
+ * Log a message at the WARN level according to the specified format and
+ * arguments.
+ *
+ * <p>
+ * This form avoids superfluous object creation when the logger is disabled
+ * for the WARN level.
+ * </p>
+ *
+ * @param format
+ * the format string
+ * @param argA
+ * the first argument
+ * @param argB
+ * the second argument
+ */
+ @Override
+ public void warn(String format, Object argA, Object argB) {
+ logger.warn(FQCN, format, argA, argB);
+ }
+
+ /**
+ * Log a message at level WARN according to the specified format and
+ * arguments.
+ *
+ * <p>
+ * This form avoids superfluous object creation when the logger is disabled
+ * for the WARN level.
+ * </p>
+ *
+ * @param format
+ * the format string
+ * @param argArray
+ * an array of arguments
+ */
+ @Override
+ public void warn(String format, Object... argArray) {
+ logger.warn(FQCN, format, argArray);
+ }
+
+ /**
+ * Log an exception (throwable) at the WARN level with an accompanying
+ * message.
+ *
+ * @param msg
+ * the message accompanying the exception
+ * @param t
+ * the exception (throwable) to log
+ */
+ @Override
+ public void warn(String msg, Throwable t) {
+ logger.warn(FQCN, msg, t);
+ }
+
+ /**
+ * Is this logger instance enabled for level ERROR?
+ *
+ * @return True if this Logger is enabled for level ERROR, false otherwise.
+ */
+ @Override
+ public boolean isErrorEnabled() {
+ return logger.isErrorEnabled();
+ }
+
+ /**
+ * Log a message object at the ERROR level.
+ *
+ * @param msg
+ * - the message object to be logged
+ */
+ @Override
+ public void error(String msg) {
+ logger.error(FQCN, msg);
+ }
+
+ /**
+ * Log a message at the ERROR level according to the specified format and
+ * argument.
+ *
+ * <p>
+ * This form avoids superfluous object creation when the logger is disabled
+ * for the ERROR level.
+ * </p>
+ *
+ * @param format
+ * the format string
+ * @param arg
+ * the argument
+ */
+ @Override
+ public void error(String format, Object arg) {
+ logger.error(FQCN, format, arg);
+ }
+
+ /**
+ * Log a message at the ERROR level according to the specified format and
+ * arguments.
+ *
+ * <p>
+ * This form avoids superfluous object creation when the logger is disabled
+ * for the ERROR level.
+ * </p>
+ *
+ * @param format
+ * the format string
+ * @param argA
+ * the first argument
+ * @param argB
+ * the second argument
+ */
+ @Override
+ public void error(String format, Object argA, Object argB) {
+ logger.error(FQCN, format, argA, argB);
+ }
+
+ /**
+ * Log a message at level ERROR according to the specified format and
+ * arguments.
+ *
+ * <p>
+ * This form avoids superfluous object creation when the logger is disabled
+ * for the ERROR level.
+ * </p>
+ *
+ * @param format
+ * the format string
+ * @param argArray
+ * an array of arguments
+ */
+ @Override
+ public void error(String format, Object... argArray) {
+ logger.error(FQCN, format, argArray);
+ }
+
+ /**
+ * Log an exception (throwable) at the ERROR level with an accompanying
+ * message.
+ *
+ * @param msg
+ * the message accompanying the exception
+ * @param t
+ * the exception (throwable) to log
+ */
+ @Override
+ public void error(String msg, Throwable t) {
+ logger.error(FQCN, msg, t);
+ }
+}
+
+
diff --git a/src/userdev/java/net/minecraftforge/userdev/LaunchTesting.java b/src/userdev/java/net/minecraftforge/userdev/LaunchTesting.java
index d5a8041f5..2454d80ed 100644
--- a/src/userdev/java/net/minecraftforge/userdev/LaunchTesting.java
+++ b/src/userdev/java/net/minecraftforge/userdev/LaunchTesting.java
@@ -34,6 +34,8 @@ import java.util.Locale;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+import io.netty.util.internal.logging.InternalLoggerFactory;
+import net.minecraftforge.logging.ForgeNettyLogger;
import org.apache.logging.log4j.LogManager;
public class LaunchTesting
@@ -98,6 +100,8 @@ public class LaunchTesting
throw new IllegalArgumentException("Unknown value for 'target' property: " + target);
}
+ InternalLoggerFactory.setDefaultFactory(ForgeNettyLogger.Factory.INSTANCE);
+
Launcher.main(lst.getArguments());
Thread.sleep(10000);// Why do we have this? -Lex 03/06/19
}
--
2.21.0.windows.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment