Skip to content

Commit

Permalink
Fix logging is broken in Minecraft 1.20
Browse files Browse the repository at this point in the history
  • Loading branch information
yushijinhun committed Jun 11, 2023
1 parent 18a0ce2 commit b680492
Showing 1 changed file with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2022 Haowei Wen <[email protected]> and contributors
* Copyright (C) 2023 Haowei Wen <[email protected]> and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
Expand Down Expand Up @@ -128,7 +128,18 @@ private static void registerLogHandle(ClassLoader cl) throws ReflectiveOperation
Array.set(appenderRefs, 0, appenderRef);

Object loggerConfig;
{
try {
Object builder = classLoggerConfig.getDeclaredMethod("newBuilder").invoke(null);
Class<?> classBuilder = cl.loadClass("org.apache.logging.log4j.core.config.LoggerConfig$Builder");
classBuilder.getMethod("withConfig", classConfiguration).invoke(builder, configuration);
classBuilder.getMethod("withAdditivity", boolean.class).invoke(builder, false);
classBuilder.getMethod("withLevel", classLevel).invoke(builder, classLevel.getDeclaredField("ALL").get(null));
classBuilder.getMethod("withLoggerName", String.class).invoke(builder, loggerName);
classBuilder.getMethod("withIncludeLocation", String.class).invoke(builder, authlibPackageName);
classBuilder.getMethod("withRefs", appenderRefs.getClass()).invoke(builder, appenderRefs);
loggerConfig = classBuilder.getMethod("build").invoke(builder);
} catch (NoSuchMethodException ex) {
ex.printStackTrace();
Map<String, Object> values = new HashMap<>();
values.put("additivity", false);
values.put("level", classLevel.getDeclaredField("ALL").get(null));
Expand Down

0 comments on commit b680492

Please sign in to comment.