Skip to content

Conversation

CiiLu
Copy link
Contributor

@CiiLu CiiLu commented Jul 29, 2025

在崩溃群排查错误的过程中,因为 HMCL 给游戏提供的 log4j2.xml 可能会丢失一些需要的信息,需要用户手动替换一个日志级别低的 log4j2 文件

先下载这个文件,把它放到游戏文件夹里的 config 文件夹里 https://gitee.com/zekerzhayard/HMCL-KOOK-Resources/releases/download/2024.2.5/log4j2.xml ,然后在 HMCL 的「游戏特定设置」(不是全局游戏设置)里的「Java 虚拟机参数」里加 -Dlog4j2.formatMsgNoLookups=false -Dlog4j.configurationFile=config/log4j2.xml

让用户自己操作非常容易出错且沟通成本高,因此需要一个快捷选项方便用户使用。本 PR 在游戏高级设置里添加了相关选项,可以一键切换到预设的低级别 log4j2 配置文件
图片

@Glavo
Copy link
Member

Glavo commented Jul 29, 2025

关于 log4j,我们正在考虑是否可以不再打包 log4j2.xml,而是遵循默认的配置。

@CiiLu CiiLu requested a review from 3gf8jv4dv July 30, 2025 01:43
@Glavo
Copy link
Member

Glavo commented Sep 4, 2025

我觉得这个选项名字不是很好,叫「输出调试日志」可能会更合适。而且我感觉它应该放在「查看日志」的下面,而不是高级选项里。

@CiiLu CiiLu changed the title 添加使用调试级别 log4j2 配置文件选项 添加输出游戏调试日志选项 Sep 12, 2025
FXUtils.unbind(txtServerIP, lastVersionSetting.serverIpProperty());
chkAutoAllocate.selectedProperty().unbindBidirectional(lastVersionSetting.autoMemoryProperty());
chkFullscreen.selectedProperty().unbindBidirectional(lastVersionSetting.fullscreenProperty());
useDebugLogOutputPane.selectedProperty().unbindBidirectional(versionSetting.useDebugLogOutputProperty());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

你这里 unbind 错东西了。unbind 的目标应该是 lastVersionSetting 的属性,而不是 versionSetting 的属性 。

# Conflicts:
#	HMCLCore/src/main/java/org/jackhuang/hmcl/launch/DefaultLauncher.java
InputStream source;
if (GameVersionNumber.asGameVersion(repository.getGameVersion(version)).compareTo("1.12") < 0) {
if (options.isShowDebugLog()) {
source = DefaultLauncher.class.getResourceAsStream("/assets/game/log4j2-debug.xml");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

你确定你的这个配置文件对 Minecraft 1.7+ 都生效吗?我怎么看到这个文件里用了高版本 Log4j 才有的功能?

String sourcePath = "/assets/game/log4j2-";

if (GameVersionNumber.asGameVersion(repository.getGameVersion(version)).compareTo("1.12") < 0) {
sourcePath += "1.7";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不建议使用 += 拼接字符串,应当用 StringBuilder 来拼接。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants