Skip to content

Fix #4240: 旧版MC日志把每一条都给算成error#6304

Open
Wulian233 wants to merge 5 commits into
HMCL-dev:mainfrom
Wulian233:main
Open

Fix #4240: 旧版MC日志把每一条都给算成error#6304
Wulian233 wants to merge 5 commits into
HMCL-dev:mainfrom
Wulian233:main

Conversation

@Wulian233

@Wulian233 Wulian233 commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

update:下面评论所有的版本都解决了

image

Close #4240

老版本日志的级别都是本地化中文的,所以还需要根据这个判断日志级别,不能不改Log4jLevel.java,否则全部日志都会变成信息级别

@woshixiaoheizi114514

Copy link
Copy Markdown

艹,竟然有人想起来这条issue

@woshixiaoheizi114514

woshixiaoheizi114514 commented Jul 4, 2026

Copy link
Copy Markdown

实际上原版1.6.4日志也是全算成error(info一觉起来成error)的。。。
屏幕截图 2026-07-04 202852
(虽然我更多时候遇到此类情况并不是1.6.4forge,而是MITE模组)

@woshixiaoheizi114514

woshixiaoheizi114514 commented Jul 4, 2026

Copy link
Copy Markdown

后面又测了几个版本,1.5.2也是这种结构,但是再早(从1.1开始)就是图一这种了(艹上传顺序反了)
屏幕截图 2026-07-04 204002
屏幕截图 2026-07-04 205438

@Wulian233

Copy link
Copy Markdown
Contributor Author

你能给一个所有日志都被算为error的一个版本范围吗

@woshixiaoheizi114514

Copy link
Copy Markdown
屏幕截图 2026-07-04 212250

阿尔法1.0.1也有

@woshixiaoheizi114514

Copy link
Copy Markdown

正在找最早能实现的版本ing(因为rd版本日志已经没啥用了)
屏幕截图 2026-07-04 212410

@woshixiaoheizi114514

Copy link
Copy Markdown

目前理论最早出现的是classic0.0.11a(貌似是镜像源能下到最早的classic了)
屏幕截图 2026-07-04 212707

@Wulian233 Wulian233 changed the title Fix #4240: MC版本为1.6.4时,日志把每一条都给算成error Fix #4240: 旧版MC日志把每一条都给算成error Jul 5, 2026
@Wulian233

Copy link
Copy Markdown
Contributor Author

update:上面评论所有的版本都解决了,可以随时审查合并

Comment thread HMCLCore/src/main/java/org/jackhuang/hmcl/util/Log4jLevel.java Outdated
@Wulian233

Copy link
Copy Markdown
Contributor Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request refactors the log level guessing logic in Log4jLevel.java by introducing helper methods and predefined marker arrays to simplify the parsing code. It also updates LauncherHelper.java to leverage these new methods. The review identified two critical issues: first, redundant calls to guessLevel in LauncherHelper.java that degrade performance and can lead to a potential NullPointerException when level remains null; second, a regression in Log4jLevel.java where the check for [STDERR] was omitted during the refactoring of error markers.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread HMCL/src/main/java/org/jackhuang/hmcl/game/LauncherHelper.java
Comment thread HMCLCore/src/main/java/org/jackhuang/hmcl/util/Log4jLevel.java Outdated
@Wulian233
Wulian233 requested a review from Glavo July 10, 2026 12:14
@github-actions github-actions Bot added the 100+ label Jul 17, 2026
@Wulian233

Copy link
Copy Markdown
Contributor Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request refactors the log level guessing logic in Log4jLevel.java by introducing helper methods and predefined marker arrays to simplify parsing. In LauncherHelper.java, the log level guessing is updated to handle error streams. The review feedback highlights two improvement opportunities: first, Level.getLocalizedName() depends on the JVM locale and may fail to match Chinese localized logs on non-Chinese systems, so explicit Chinese markers should be added; second, there is a redundant call to Log4jLevel.guessLevel(log) in LauncherHelper.java when level is already determined to be null, which can be simplified to directly use Log4jLevel.INFO.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread HMCLCore/src/main/java/org/jackhuang/hmcl/util/Log4jLevel.java
Comment on lines +937 to 942
Log4jLevel level = log.startsWith("[authlib-injector]")
? Log4jLevel.guessLevel(log)
: Log4jLevel.guessLevel(log, isErrorStream);
if (showLogs) {
if (level == null)
level = Lang.requireNonNullElse(Log4jLevel.guessLevel(log), Log4jLevel.INFO);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

LauncherHelper.java 中,如果 levelnull,代码会再次调用 Log4jLevel.guessLevel(log)。然而,在第 937-939 行中,level 已经是通过 Log4jLevel.guessLevel 计算出来的。如果它为 null,再次调用也必然返回 null

因此,这里可以直接使用 Log4jLevel.INFO 作为默认值,避免重复进行正则匹配,从而提高日志处理的效率。

Suggested change
Log4jLevel level = log.startsWith("[authlib-injector]")
? Log4jLevel.guessLevel(log)
: Log4jLevel.guessLevel(log, isErrorStream);
if (showLogs) {
if (level == null)
level = Lang.requireNonNullElse(Log4jLevel.guessLevel(log), Log4jLevel.INFO);
Log4jLevel level = log.startsWith("[authlib-injector]")
? Log4jLevel.guessLevel(log)
: Log4jLevel.guessLevel(log, isErrorStream);
if (showLogs) {
if (level == null)
level = Log4jLevel.INFO;

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] 当mc版本为1.6.4时,日志把每一条都给算成error

3 participants