From b1775b5e752dede0281e521080da0a1e71d295c7 Mon Sep 17 00:00:00 2001 From: creeper123123321 Date: Tue, 21 Aug 2018 13:54:39 -0300 Subject: [PATCH] Logger, Channel#newSucceededFuture --- .../creeper123123321/viarift/ViaRift.java | 5 ++ .../viarift/platform/VRPlatform.java | 3 +- .../viarift/platform/VRUserConnection.java | 2 +- .../viarift/util/JLoggerToLog4j.java | 77 +++++++++++++++++++ 4 files changed, 85 insertions(+), 2 deletions(-) create mode 100644 src/main/java/com/github/creeper123123321/viarift/util/JLoggerToLog4j.java diff --git a/src/main/java/com/github/creeper123123321/viarift/ViaRift.java b/src/main/java/com/github/creeper123123321/viarift/ViaRift.java index 7b62f23..52dff2c 100644 --- a/src/main/java/com/github/creeper123123321/viarift/ViaRift.java +++ b/src/main/java/com/github/creeper123123321/viarift/ViaRift.java @@ -3,6 +3,9 @@ package com.github.creeper123123321.viarift; import com.github.creeper123123321.viarift.platform.VRInjector; import com.github.creeper123123321.viarift.platform.VRLoader; import com.github.creeper123123321.viarift.platform.VRPlatform; +import com.github.creeper123123321.viarift.util.JLoggerToLog4j; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.dimdev.riftloader.listener.InitializationListener; import org.spongepowered.asm.launch.MixinBootstrap; import org.spongepowered.asm.mixin.Mixins; @@ -11,6 +14,8 @@ import us.myles.ViaVersion.api.Via; public class ViaRift implements InitializationListener { public static int fakeServerVersion = 393; // TODO + public static final Logger LOGGER = LogManager.getLogger(); + public static final java.util.logging.Logger JLOGGER = new JLoggerToLog4j(LOGGER); @Override public void onInitialization() { MixinBootstrap.init(); diff --git a/src/main/java/com/github/creeper123123321/viarift/platform/VRPlatform.java b/src/main/java/com/github/creeper123123321/viarift/platform/VRPlatform.java index 03d78b3..589cba1 100644 --- a/src/main/java/com/github/creeper123123321/viarift/platform/VRPlatform.java +++ b/src/main/java/com/github/creeper123123321/viarift/platform/VRPlatform.java @@ -1,5 +1,6 @@ package com.github.creeper123123321.viarift.platform; +import com.github.creeper123123321.viarift.ViaRift; import com.github.creeper123123321.viarift.util.DelayedRunnable; import com.github.creeper123123321.viarift.util.LoopRunnable; import net.minecraft.client.Minecraft; @@ -19,7 +20,7 @@ import java.util.logging.Logger; public class VRPlatform implements ViaPlatform { @Override public Logger getLogger() { - return Logger.getLogger("ViaRift"); + return ViaRift.JLOGGER; } @Override diff --git a/src/main/java/com/github/creeper123123321/viarift/platform/VRUserConnection.java b/src/main/java/com/github/creeper123123321/viarift/platform/VRUserConnection.java index 2f6ac10..c5deee8 100644 --- a/src/main/java/com/github/creeper123123321/viarift/platform/VRUserConnection.java +++ b/src/main/java/com/github/creeper123123321/viarift/platform/VRUserConnection.java @@ -60,6 +60,6 @@ public class VRUserConnection extends UserConnection { } catch (Exception e) { e.printStackTrace(); } - return null; + return channel.newSucceededFuture(); } } diff --git a/src/main/java/com/github/creeper123123321/viarift/util/JLoggerToLog4j.java b/src/main/java/com/github/creeper123123321/viarift/util/JLoggerToLog4j.java new file mode 100644 index 0000000..2eda45d --- /dev/null +++ b/src/main/java/com/github/creeper123123321/viarift/util/JLoggerToLog4j.java @@ -0,0 +1,77 @@ +package com.github.creeper123123321.viarift.util; + +import java.util.logging.Level; +import java.util.logging.LogRecord; +import java.util.logging.Logger; + +public class JLoggerToLog4j extends Logger { + private final org.apache.logging.log4j.Logger base; + + public JLoggerToLog4j(org.apache.logging.log4j.Logger logger) { + super("logger", null); + this.base = logger; + } + + public void log(LogRecord record) { + this.log(record.getLevel(), record.getMessage()); + } + + public void log(Level level, String msg) { + if (level == Level.FINE) { + this.base.debug(msg); + } else if (level == Level.WARNING) { + this.base.warn(msg); + } else if (level == Level.SEVERE) { + this.base.error(msg); + } else if (level == Level.INFO) { + this.base.info(msg); + } else { + this.base.trace(msg); + } + + } + + public void log(Level level, String msg, Object param1) { + if (level == Level.FINE) { + this.base.debug(msg, param1); + } else if (level == Level.WARNING) { + this.base.warn(msg, param1); + } else if (level == Level.SEVERE) { + this.base.error(msg, param1); + } else if (level == Level.INFO) { + this.base.info(msg, param1); + } else { + this.base.trace(msg, param1); + } + + } + + public void log(Level level, String msg, Object[] params) { + if (level == Level.FINE) { + this.base.debug(msg, params); + } else if (level == Level.WARNING) { + this.base.warn(msg, params); + } else if (level == Level.SEVERE) { + this.base.error(msg, params); + } else if (level == Level.INFO) { + this.base.info(msg, params); + } else { + this.base.trace(msg, params); + } + } + + public void log(Level level, String msg, Throwable params) { + if (level == Level.FINE) { + this.base.debug(msg, params); + } else if (level == Level.WARNING) { + this.base.warn(msg, params); + } else if (level == Level.SEVERE) { + this.base.error(msg, params); + } else if (level == Level.INFO) { + this.base.info(msg, params); + } else { + this.base.trace(msg, params); + } + + } +}