From fe204f0606b59d7d1d0217cbc63c0ffd8bc99f33 Mon Sep 17 00:00:00 2001 From: Paint_Ninja Date: Mon, 8 Apr 2024 14:31:20 +0100 Subject: [PATCH] Call `getLogger()` only once in entrypoint class (#1) Reflectively walking the stack every time we log something in the entrypoint class is unnecessary... --- src/main/java/cpw/mods/modlauncher/Launcher.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main/java/cpw/mods/modlauncher/Launcher.java b/src/main/java/cpw/mods/modlauncher/Launcher.java index fb8da34..0b8109f 100644 --- a/src/main/java/cpw/mods/modlauncher/Launcher.java +++ b/src/main/java/cpw/mods/modlauncher/Launcher.java @@ -16,6 +16,7 @@ import cpw.mods.modlauncher.api.ITransformationService.Resource; import cpw.mods.modlauncher.api.TypesafeMap; import cpw.mods.modlauncher.serviceapi.ILaunchPluginService; +import org.apache.logging.log4j.Logger; import java.util.ArrayList; import java.util.HashMap; @@ -30,6 +31,7 @@ */ public class Launcher { public static Launcher INSTANCE; + private static final Logger LOGGER = LogManager.getLogger(); private final TypesafeMap blackboard; private final TransformationServicesHandler transformationServicesHandler; private final Environment environment; @@ -43,7 +45,7 @@ public class Launcher { private Launcher() { INSTANCE = this; - LogManager.getLogger().info(MODLAUNCHER,"ModLauncher {} starting: java version {} by {}; OS {} arch {} version {}", ()->IEnvironment.class.getPackage().getImplementationVersion(), () -> System.getProperty("java.version"), ()->System.getProperty("java.vendor"), ()->System.getProperty("os.name"), ()->System.getProperty("os.arch"), ()->System.getProperty("os.version")); + LOGGER.info(MODLAUNCHER,"ModLauncher {} starting: java version {} by {}; OS {} arch {} version {}", ()->IEnvironment.class.getPackage().getImplementationVersion(), () -> System.getProperty("java.version"), ()->System.getProperty("java.vendor"), ()->System.getProperty("os.name"), ()->System.getProperty("os.arch"), ()->System.getProperty("os.version")); this.moduleLayerHandler = new ModuleLayerHandler(); this.launchService = new LaunchServiceHandler(this.moduleLayerHandler); this.blackboard = new TypesafeMap(); @@ -68,8 +70,8 @@ public static void main(String... args) { JVM information: %s %s %s """, props.getProperty("java.vm.vendor"), props.getProperty("java.vm.name"), props.getProperty("java.vm.version")); } - LogManager.getLogger().info(MODLAUNCHER,"ModLauncher running: args {}", () -> LaunchServiceHandler.hideAccessToken(args)); - LogManager.getLogger().info(MODLAUNCHER, "JVM identified as {} {} {}", props.getProperty("java.vm.vendor"), props.getProperty("java.vm.name"), props.getProperty("java.vm.version")); + LOGGER.info(MODLAUNCHER,"ModLauncher running: args {}", () -> LaunchServiceHandler.hideAccessToken(args)); + LOGGER.info(MODLAUNCHER, "JVM identified as {} {} {}", props.getProperty("java.vm.vendor"), props.getProperty("java.vm.name"), props.getProperty("java.vm.version")); new Launcher().run(args); }