From 2d6e01fcf91afed121253b421ee28fa4a11e51cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=BE=9E=E5=BA=90?= <109708109+CiiLu@users.noreply.github.com> Date: Sun, 14 Dec 2025 20:49:23 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=BE=93=E5=87=BA=E6=B8=B8?= =?UTF-8?q?=E6=88=8F=E8=B0=83=E8=AF=95=E6=97=A5=E5=BF=97=E9=80=89=E9=A1=B9?= =?UTF-8?q?=20(#4144)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hmcl/game/HMCLGameRepository.java | 1 + .../hmcl/setting/VersionSetting.java | 16 ++++++++ .../hmcl/ui/versions/VersionSettingsPage.java | 7 ++++ .../resources/assets/lang/I18N.properties | 1 + .../resources/assets/lang/I18N_zh.properties | 1 + .../assets/lang/I18N_zh_CN.properties | 1 + .../jackhuang/hmcl/game/LaunchOptions.java | 9 +++++ .../hmcl/launch/DefaultLauncher.java | 20 +++++++--- .../assets/game/log4j2-1.12-debug.xml | 37 +++++++++++++++++++ .../assets/game/log4j2-1.7-debug.xml | 36 ++++++++++++++++++ 10 files changed, 124 insertions(+), 5 deletions(-) create mode 100644 HMCLCore/src/main/resources/assets/game/log4j2-1.12-debug.xml create mode 100644 HMCLCore/src/main/resources/assets/game/log4j2-1.7-debug.xml diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/game/HMCLGameRepository.java b/HMCL/src/main/java/org/jackhuang/hmcl/game/HMCLGameRepository.java index bec53d561..87eac5d85 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/game/HMCLGameRepository.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/game/HMCLGameRepository.java @@ -428,6 +428,7 @@ public final class HMCLGameRepository extends DefaultGameRepository { .setNativesDir(vs.getNativesDir()) .setProcessPriority(vs.getProcessPriority()) .setRenderer(vs.getRenderer()) + .setEnableDebugLogOutput(vs.isEnableDebugLogOutput()) .setUseNativeGLFW(vs.isUseNativeGLFW()) .setUseNativeOpenAL(vs.isUseNativeOpenAL()) .setDaemon(!makeLaunchScript && vs.getLauncherVisibility().isDaemon()) diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/setting/VersionSetting.java b/HMCL/src/main/java/org/jackhuang/hmcl/setting/VersionSetting.java index edb51582e..3443e57c6 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/setting/VersionSetting.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/setting/VersionSetting.java @@ -459,6 +459,20 @@ public final class VersionSetting implements Cloneable, Observable { showLogsProperty.set(showLogs); } + private final BooleanProperty enableDebugLogOutputProperty = new SimpleBooleanProperty(this, "enableDebugLogOutput", false); + + public BooleanProperty enableDebugLogOutputProperty() { + return enableDebugLogOutputProperty; + } + + public boolean isEnableDebugLogOutput() { + return enableDebugLogOutputProperty.get(); + } + + public void setEnableDebugLogOutput(boolean u) { + this.enableDebugLogOutputProperty.set(u); + } + // Minecraft settings. private final StringProperty serverIpProperty = new SimpleStringProperty(this, "serverIp", ""); @@ -776,6 +790,7 @@ public final class VersionSetting implements Cloneable, Observable { obj.addProperty("notCheckJVM", src.isNotCheckJVM()); obj.addProperty("notPatchNatives", src.isNotPatchNatives()); obj.addProperty("showLogs", src.isShowLogs()); + obj.addProperty("enableDebugLogOutput", src.isEnableDebugLogOutput()); obj.addProperty("gameDir", src.getGameDir()); obj.addProperty("launcherVisibility", src.getLauncherVisibility().ordinal()); obj.addProperty("processPriority", src.getProcessPriority().ordinal()); @@ -847,6 +862,7 @@ public final class VersionSetting implements Cloneable, Observable { vs.setNotCheckJVM(Optional.ofNullable(obj.get("notCheckJVM")).map(JsonElement::getAsBoolean).orElse(false)); vs.setNotPatchNatives(Optional.ofNullable(obj.get("notPatchNatives")).map(JsonElement::getAsBoolean).orElse(false)); vs.setShowLogs(Optional.ofNullable(obj.get("showLogs")).map(JsonElement::getAsBoolean).orElse(false)); + vs.setEnableDebugLogOutput(Optional.ofNullable(obj.get("enableDebugLogOutput")).map(JsonElement::getAsBoolean).orElse(false)); vs.setLauncherVisibility(parseJsonPrimitive(obj.getAsJsonPrimitive("launcherVisibility"), LauncherVisibility.class, LauncherVisibility.HIDE)); vs.setProcessPriority(parseJsonPrimitive(obj.getAsJsonPrimitive("processPriority"), ProcessPriority.class, ProcessPriority.NORMAL)); vs.setUseNativeGLFW(Optional.ofNullable(obj.get("useNativeGLFW")).map(JsonElement::getAsBoolean).orElse(false)); diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/VersionSettingsPage.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/VersionSettingsPage.java index d92b6fc9d..6b39dd823 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/VersionSettingsPage.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/VersionSettingsPage.java @@ -111,6 +111,7 @@ public final class VersionSettingsPage extends StackPane implements DecoratorPag private final MultiFileItem.FileOption gameDirCustomOption; private final JFXComboBox cboProcessPriority; private final OptionToggleButton showLogsPane; + private final OptionToggleButton enableDebugLogOutputPane; private final ImagePickerItem iconPickerItem; private final ChangeListener> javaListChangeListener; @@ -410,6 +411,9 @@ public final class VersionSettingsPage extends StackPane implements DecoratorPag showLogsPane = new OptionToggleButton(); showLogsPane.setTitle(i18n("settings.show_log")); + enableDebugLogOutputPane = new OptionToggleButton(); + enableDebugLogOutputPane.setTitle(i18n("settings.enable_debug_log_output")); + BorderPane processPriorityPane = new BorderPane(); { Label label = new Label(i18n("settings.advanced.process_priority")); @@ -474,6 +478,7 @@ public final class VersionSettingsPage extends StackPane implements DecoratorPag launcherVisibilityPane, dimensionPane, showLogsPane, + enableDebugLogOutputPane, processPriorityPane, serverPane, showAdvancedSettingPane @@ -551,6 +556,7 @@ public final class VersionSettingsPage extends StackPane implements DecoratorPag chkAutoAllocate.selectedProperty().unbindBidirectional(lastVersionSetting.autoMemoryProperty()); chkFullscreen.selectedProperty().unbindBidirectional(lastVersionSetting.fullscreenProperty()); showLogsPane.selectedProperty().unbindBidirectional(lastVersionSetting.showLogsProperty()); + enableDebugLogOutputPane.selectedProperty().unbindBidirectional(lastVersionSetting.enableDebugLogOutputProperty()); FXUtils.unbindEnum(cboLauncherVisibility, lastVersionSetting.launcherVisibilityProperty()); FXUtils.unbindEnum(cboProcessPriority, lastVersionSetting.processPriorityProperty()); @@ -585,6 +591,7 @@ public final class VersionSettingsPage extends StackPane implements DecoratorPag chkAutoAllocate.selectedProperty().bindBidirectional(versionSetting.autoMemoryProperty()); chkFullscreen.selectedProperty().bindBidirectional(versionSetting.fullscreenProperty()); showLogsPane.selectedProperty().bindBidirectional(versionSetting.showLogsProperty()); + enableDebugLogOutputPane.selectedProperty().bindBidirectional(versionSetting.enableDebugLogOutputProperty()); FXUtils.bindEnum(cboLauncherVisibility, versionSetting.launcherVisibilityProperty()); FXUtils.bindEnum(cboProcessPriority, versionSetting.processPriorityProperty()); diff --git a/HMCL/src/main/resources/assets/lang/I18N.properties b/HMCL/src/main/resources/assets/lang/I18N.properties index 5fabd687e..1e18d2def 100644 --- a/HMCL/src/main/resources/assets/lang/I18N.properties +++ b/HMCL/src/main/resources/assets/lang/I18N.properties @@ -1412,6 +1412,7 @@ settings.memory.unit.mib=MiB settings.memory.used_per_total=%1$.1f GiB Used / %2$.1f GiB Total settings.physical_memory=Physical Memory Size settings.show_log=Show Logs +settings.enable_debug_log_output=Output debug log settings.tabs.installers=Loaders settings.take_effect_after_restart=Applies After Restart settings.type=Settings Type of Instance diff --git a/HMCL/src/main/resources/assets/lang/I18N_zh.properties b/HMCL/src/main/resources/assets/lang/I18N_zh.properties index 6ccc3dd27..154323941 100644 --- a/HMCL/src/main/resources/assets/lang/I18N_zh.properties +++ b/HMCL/src/main/resources/assets/lang/I18N_zh.properties @@ -1200,6 +1200,7 @@ settings.memory.unit.mib=MiB settings.memory.used_per_total=已使用 %1$.1f GiB / 總記憶體 %2$.1f GiB settings.physical_memory=實體記憶體大小 settings.show_log=查看日誌 +settings.enable_debug_log_output=輸出除錯日誌 settings.tabs.installers=自動安裝 settings.take_effect_after_restart=重啟後生效 settings.type=實例遊戲設定類型 diff --git a/HMCL/src/main/resources/assets/lang/I18N_zh_CN.properties b/HMCL/src/main/resources/assets/lang/I18N_zh_CN.properties index 0e2e57588..d0c99a620 100644 --- a/HMCL/src/main/resources/assets/lang/I18N_zh_CN.properties +++ b/HMCL/src/main/resources/assets/lang/I18N_zh_CN.properties @@ -1210,6 +1210,7 @@ settings.memory.unit.mib=MiB settings.memory.used_per_total=设备中已使用 %1$.1f GiB / 设备总内存 %2$.1f GiB settings.physical_memory=物理内存大小 settings.show_log=查看日志 +settings.enable_debug_log_output=输出调试日志 settings.tabs.installers=自动安装 settings.take_effect_after_restart=重启后生效 settings.type=实例游戏设置类型 diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/game/LaunchOptions.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/game/LaunchOptions.java index 93d9a41b4..fb46fd127 100644 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/game/LaunchOptions.java +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/game/LaunchOptions.java @@ -64,6 +64,7 @@ public class LaunchOptions implements Serializable { private Renderer renderer = Renderer.DEFAULT; private boolean useNativeGLFW; private boolean useNativeOpenAL; + private boolean enableDebugLogOutput; private boolean daemon; /** @@ -282,6 +283,10 @@ public class LaunchOptions implements Serializable { return useNativeOpenAL; } + public boolean isEnableDebugLogOutput() { + return enableDebugLogOutput; + } + /** * Will launcher keeps alive after game launched or not. */ @@ -497,5 +502,9 @@ public class LaunchOptions implements Serializable { return this; } + public Builder setEnableDebugLogOutput(boolean u) { + options.enableDebugLogOutput = u; + return this; + } } } diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/launch/DefaultLauncher.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/launch/DefaultLauncher.java index 09489492b..3c2f4ed91 100644 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/launch/DefaultLauncher.java +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/launch/DefaultLauncher.java @@ -149,7 +149,7 @@ public class DefaultLauncher extends Launcher { res.addDefault("-Dcom.sun.jndi.cosnaming.object.trustURLCodebase=", "false"); String formatMsgNoLookups = res.addDefault("-Dlog4j2.formatMsgNoLookups=", "true"); - if (!"-Dlog4j2.formatMsgNoLookups=false".equals(formatMsgNoLookups) && isUsingLog4j()) { + if (isUsingLog4j() && (options.isEnableDebugLogOutput() || !"-Dlog4j2.formatMsgNoLookups=false".equals(formatMsgNoLookups))) { res.addDefault("-Dlog4j.configurationFile=", FileUtils.getAbsolutePath(getLog4jConfigurationFile())); } @@ -421,14 +421,24 @@ public class DefaultLauncher extends Launcher { public void extractLog4jConfigurationFile() throws IOException { Path targetFile = getLog4jConfigurationFile(); - InputStream source; + + String sourcePath; + if (GameVersionNumber.asGameVersion(repository.getGameVersion(version)).compareTo("1.12") < 0) { - source = DefaultLauncher.class.getResourceAsStream("/assets/game/log4j2-1.7.xml"); + if (options.isEnableDebugLogOutput()) { + sourcePath = "/assets/game/log4j2-1.7-debug.xml"; + } else { + sourcePath = "/assets/game/log4j2-1.7.xml"; + } } else { - source = DefaultLauncher.class.getResourceAsStream("/assets/game/log4j2-1.12.xml"); + if (options.isEnableDebugLogOutput()) { + sourcePath = "/assets/game/log4j2-1.12-debug.xml"; + } else { + sourcePath = "/assets/game/log4j2-1.12.xml"; + } } - try (InputStream input = source) { + try (InputStream input = DefaultLauncher.class.getResourceAsStream(sourcePath)) { Files.copy(input, targetFile, StandardCopyOption.REPLACE_EXISTING); } } diff --git a/HMCLCore/src/main/resources/assets/game/log4j2-1.12-debug.xml b/HMCLCore/src/main/resources/assets/game/log4j2-1.12-debug.xml new file mode 100644 index 000000000..088bccaba --- /dev/null +++ b/HMCLCore/src/main/resources/assets/game/log4j2-1.12-debug.xml @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/HMCLCore/src/main/resources/assets/game/log4j2-1.7-debug.xml b/HMCLCore/src/main/resources/assets/game/log4j2-1.7-debug.xml new file mode 100644 index 000000000..7fabc697d --- /dev/null +++ b/HMCLCore/src/main/resources/assets/game/log4j2-1.7-debug.xml @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +