mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-19 11:59:25 +00:00
Fix inaccurate main thread name shown in client log (#5078)
This commit is contained in:
1 parent
d16472d0ba
commit
8d372f95f2
2 files changed
+67
-37
No files matched your search
@@ -25,6 +25,7 @@ import static net.minecraftforge.common.ForgeVersion.Status.BETA_OUTDATED;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.lang.reflect.Field;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.FloatBuffer;
|
||||
import java.util.Map;
|
||||
@@ -135,6 +136,8 @@ import net.minecraftforge.fml.client.registry.ClientRegistry;
|
||||
import net.minecraftforge.fml.common.FMLLog;
|
||||
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
import org.apache.logging.log4j.core.async.ThreadNameCachingStrategy;
|
||||
import org.apache.logging.log4j.core.impl.ReusableLogEventFactory;
|
||||
import org.lwjgl.BufferUtils;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import org.lwjgl.opengl.GL20;
|
||||
@@ -781,4 +784,23 @@ public class ForgeHooksClient
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Resets cached thread fields in ThreadNameCachingStrategy and ReusableLogEventFactory to be repopulated during their next access.
|
||||
// This serves a workaround for no built-in method of triggering this type of refresh as brought up by LOG4J2-2178.
|
||||
public static void invalidateLog4jThreadCache()
|
||||
{
|
||||
try
|
||||
{
|
||||
Field nameField = ThreadNameCachingStrategy.class.getDeclaredField("THREADLOCAL_NAME");
|
||||
Field logEventField = ReusableLogEventFactory.class.getDeclaredField("mutableLogEventThreadLocal");
|
||||
nameField.setAccessible(true);
|
||||
logEventField.setAccessible(true);
|
||||
((ThreadLocal<?>) nameField.get(null)).set(null);
|
||||
((ThreadLocal<?>) logEventField.get(null)).set(null);
|
||||
}
|
||||
catch (ReflectiveOperationException | NoClassDefFoundError e)
|
||||
{
|
||||
FMLLog.log.error("Unable to invalidate log4j thread cache, thread fields in logs may be inaccurate", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user