Skip to content

Commit

Permalink
new: silence launchwrapper log spam caused by lwjgl unlock
Browse files Browse the repository at this point in the history
fixes EM-923
  • Loading branch information
DJtheRedstoner committed Sep 25, 2022
1 parent 0836118 commit faa398d
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions src/main/java/club/sk1er/patcher/tweaker/PatcherTweaker.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@
import net.minecraftforge.fml.relauncher.FMLLaunchHandler;
import net.minecraftforge.fml.relauncher.IFMLLoadingPlugin;
import net.minecraftforge.fml.relauncher.ReflectionHelper;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.core.Filter;
import org.apache.logging.log4j.core.Logger;
import org.apache.logging.log4j.core.LoggerContext;
import org.apache.logging.log4j.core.filter.RegexFilter;

import javax.swing.JOptionPane;
import javax.swing.UIManager;
Expand Down Expand Up @@ -101,6 +106,42 @@ private void unlockLwjgl() {
if (!lwjglUnlock) {
System.out.println("Failed to unlock LWJGL, several fixes will not work.");
}

silenceLog4j();
}

private void silenceLog4j() {
try {
Logger logger = ((LoggerContext)LogManager.getContext(Launch.class.getClassLoader(), false)).getLogger("LaunchWrapper");

// because archloom updates log4j, we must support both log4j 2.0-beta9 and 2.8.1
RegexFilter filter = null;
for (Method method : RegexFilter.class.getMethods()) {
if (method.getName().equals("createFilter")) {
if (method.getParameterCount() == 5) {
filter = (RegexFilter) method.invoke(null,
"The jar file .* has a security seal for path .*, but that path is defined and not secure",
null, false, Filter.Result.DENY, Filter.Result.NEUTRAL);
} else if (method.getParameterCount() == 4) {
filter = (RegexFilter) method.invoke(null,
"The jar file .* has a security seal for path .*, but that path is defined and not secure",
"false", "deny", "neutral");
} else {
throw new IllegalStateException("Unknown createFilter arity " + method);
}
break;
}
}

if (filter == null) {
throw new IllegalStateException("Couldn't find createFilter method");
}

logger.addFilter(filter);
} catch (Exception e) {
System.out.println("Failed to silence log4j");
e.printStackTrace();
}
}

@SuppressWarnings({"ResultOfMethodCallIgnored", "ConstantConditions"})
Expand Down

0 comments on commit faa398d

Please sign in to comment.