From 46401b94ac6035b426dfa41cbe2029ab5a93c2b2 Mon Sep 17 00:00:00 2001 From: Christian Date: Mon, 16 Dec 2013 11:01:10 -0500 Subject: [PATCH] Use log4j2 since it is now provided by default. --- build.gradle | 3 +++ .../net/minecraft/launchwrapper/Launch.java | 21 +++++++++-------- .../launchwrapper/LaunchClassLoader.java | 11 +++++---- .../minecraft/launchwrapper/LogWrapper.java | 23 ++++++++++--------- 4 files changed, 32 insertions(+), 26 deletions(-) diff --git a/build.gradle b/build.gradle index 9a74b29..b0ac082 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,6 @@ apply plugin: 'maven' apply plugin: 'java' +apply plugin: 'eclipse' repositories { maven { @@ -16,6 +17,8 @@ dependencies { compile 'net.sf.jopt-simple:jopt-simple:4.5' compile 'org.ow2.asm:asm-debug-all:4.1' compile 'org.lwjgl.lwjgl:lwjgl:2.8.5' + compile 'org.apache.logging.log4j:log4j-core:2.0-beta9' + compile 'org.apache.logging.log4j:log4j-api:2.0-beta9' } task sourcesJar(type: Jar) { diff --git a/src/main/java/net/minecraft/launchwrapper/Launch.java b/src/main/java/net/minecraft/launchwrapper/Launch.java index 79a6600..804dce9 100644 --- a/src/main/java/net/minecraft/launchwrapper/Launch.java +++ b/src/main/java/net/minecraft/launchwrapper/Launch.java @@ -15,14 +15,15 @@ import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; -import java.util.logging.Level; + +import org.apache.logging.log4j.Level; public class Launch { private static final String DEFAULT_TWEAK = "net.minecraft.launchwrapper.VanillaTweaker"; public static File minecraftHome; public static File assetsDir; public static Map blackboard; - + public static void main(String[] args) { new Launch().launch(args); } @@ -57,7 +58,7 @@ public class Launch { // By making this object discoverable and accessible it's possible to perform // things like cascading of tweakers blackboard.put("TweakClasses", tweakClassNames); - + // This argument list will be constructed from all tweakers. It is visible here so // all tweakers can figure out if a particular argument is present, and add it if not blackboard.put("ArgumentList", argumentList); @@ -75,14 +76,14 @@ public class Launch { ITweaker primaryTweaker = null; // This loop will terminate, unless there is some sort of pathological tweaker // that reinserts itself with a new identity every pass - // It is here to allow tweakers to "push" new tweak classes onto the 'stack' of + // It is here to allow tweakers to "push" new tweak classes onto the 'stack' of // tweakers to evaluate allowing for cascaded discovery and injection of tweakers do { for (final Iterator it = tweakClassNames.iterator(); it.hasNext(); ) { final String tweakName = it.next(); // Safety check - don't reprocess something we've already visited if (allTweakerNames.contains(tweakName)) { - LogWrapper.log(Level.WARNING, "Tweak class name %s has already been visited -- skipping", tweakName); + LogWrapper.log(Level.WARN, "Tweak class name %s has already been visited -- skipping", tweakName); // remove the tweaker from the stack otherwise it will create an infinite loop it.remove(); continue; @@ -90,12 +91,12 @@ public class Launch { allTweakerNames.add(tweakName); } LogWrapper.log(Level.INFO, "Loading tweak class name %s", tweakName); - + // Ensure we allow the tweak class to load with the parent classloader classLoader.addClassLoaderExclusion(tweakName.substring(0,tweakName.lastIndexOf('.'))); final ITweaker tweaker = (ITweaker) Class.forName(tweakName, true, classLoader).newInstance(); tweakers.add(tweaker); - + // Remove the tweaker from the list of tweaker names we've processed this pass it.remove(); // If we haven't visited a tweaker yet, the first will become the 'primary' tweaker @@ -104,7 +105,7 @@ public class Launch { primaryTweaker = tweaker; } } - + // Now, iterate all the tweakers we just instantiated for (final Iterator it = tweakers.iterator(); it.hasNext(); ) { final ITweaker tweaker = it.next(); @@ -123,7 +124,7 @@ public class Launch { for (final ITweaker tweaker : allTweakers) { argumentList.addAll(Arrays.asList(tweaker.getLaunchArguments())); } - + // Finally we turn to the primary tweaker, and let it tell us where to go to launch final String launchTarget = primaryTweaker.getLaunchTarget(); final Class clazz = Class.forName(launchTarget, false, classLoader); @@ -132,7 +133,7 @@ public class Launch { LogWrapper.info("Launching wrapped minecraft {%s}", launchTarget); mainMethod.invoke(null, (Object) argumentList.toArray(new String[argumentList.size()])); } catch (Exception e) { - LogWrapper.log(Level.SEVERE, e, "Unable to launch"); + LogWrapper.log(Level.ERROR, e, "Unable to launch"); } } } diff --git a/src/main/java/net/minecraft/launchwrapper/LaunchClassLoader.java b/src/main/java/net/minecraft/launchwrapper/LaunchClassLoader.java index a8e45c8..f4b1304 100644 --- a/src/main/java/net/minecraft/launchwrapper/LaunchClassLoader.java +++ b/src/main/java/net/minecraft/launchwrapper/LaunchClassLoader.java @@ -13,7 +13,8 @@ import java.util.jar.Attributes.Name; import java.util.jar.JarEntry; import java.util.jar.JarFile; import java.util.jar.Manifest; -import java.util.logging.Level; + +import org.apache.logging.log4j.Level; public class LaunchClassLoader extends URLClassLoader { public static final int BUFFER_SIZE = 1 << 12; @@ -87,7 +88,7 @@ public class LaunchClassLoader extends URLClassLoader { renameTransformer = (IClassNameTransformer) transformer; } } catch (Exception e) { - LogWrapper.log(Level.SEVERE, e, "A critical problem occurred registering the ASM transformer class %s", transformerClassName); + LogWrapper.log(Level.ERROR, e, "A critical problem occurred registering the ASM transformer class %s", transformerClassName); } } @@ -181,7 +182,7 @@ public class LaunchClassLoader extends URLClassLoader { } catch (Throwable e) { invalidClasses.add(name); if (DEBUG) { - LogWrapper.log(Level.FINEST, e, "Exception encountered attempting classloading of %s", name); + LogWrapper.log(Level.TRACE, e, "Exception encountered attempting classloading of %s", name); } throw new ClassNotFoundException(name, e); } @@ -210,7 +211,7 @@ public class LaunchClassLoader extends URLClassLoader { output.write(data); output.close(); } catch (IOException ex) { - LogWrapper.log(Level.WARNING, ex, "Could not save transformed class \"%s\"", transformedName); + LogWrapper.log(Level.WARN, ex, "Could not save transformed class \"%s\"", transformedName); } } @@ -308,7 +309,7 @@ public class LaunchClassLoader extends URLClassLoader { System.arraycopy(buffer, 0, result, 0, totalLength); return result; } catch (Throwable t) { - LogWrapper.log(Level.WARNING, t, "Problem loading class"); + LogWrapper.log(Level.WARN, t, "Problem loading class"); return new byte[0]; } } diff --git a/src/main/java/net/minecraft/launchwrapper/LogWrapper.java b/src/main/java/net/minecraft/launchwrapper/LogWrapper.java index 1d36cc6..7037b74 100644 --- a/src/main/java/net/minecraft/launchwrapper/LogWrapper.java +++ b/src/main/java/net/minecraft/launchwrapper/LogWrapper.java @@ -1,7 +1,8 @@ package net.minecraft.launchwrapper; -import java.util.logging.Level; -import java.util.logging.Logger; +import org.apache.logging.log4j.Level; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; public class LogWrapper { public static LogWrapper log = new LogWrapper(); @@ -10,7 +11,7 @@ public class LogWrapper { private static boolean configured; private static void configureLogging() { - log.myLog = Logger.getLogger("LaunchWrapper"); + log.myLog = LogManager.getLogger("LaunchWrapper"); configured = true; } @@ -19,7 +20,7 @@ public class LogWrapper { } public static void log(String logChannel, Level level, String format, Object... data) { makeLog(logChannel); - Logger.getLogger(logChannel).log(level, String.format(format, data)); + LogManager.getLogger(logChannel).log(level, String.format(format, data)); } public static void log(Level level, String format, Object... data) { @@ -31,7 +32,7 @@ public class LogWrapper { public static void log(String logChannel, Level level, Throwable ex, String format, Object... data) { makeLog(logChannel); - Logger.getLogger(logChannel).log(level, String.format(format, data), ex); + LogManager.getLogger(logChannel).log(level, String.format(format, data), ex); } public static void log(Level level, Throwable ex, String format, Object... data) { @@ -42,11 +43,11 @@ public class LogWrapper { } public static void severe(String format, Object... data) { - log(Level.SEVERE, format, data); + log(Level.ERROR, format, data); } public static void warning(String format, Object... data) { - log(Level.WARNING, format, data); + log(Level.WARN, format, data); } public static void info(String format, Object... data) { @@ -54,18 +55,18 @@ public class LogWrapper { } public static void fine(String format, Object... data) { - log(Level.FINE, format, data); + log(Level.DEBUG, format, data); } public static void finer(String format, Object... data) { - log(Level.FINER, format, data); + log(Level.TRACE, format, data); } public static void finest(String format, Object... data) { - log(Level.FINEST, format, data); + log(Level.TRACE, format, data); } public static void makeLog(String logChannel) { - Logger.getLogger(logChannel).setParent(log.myLog); + LogManager.getLogger(logChannel); } }