Fix #4240: 旧版MC日志把每一条都给算成error#6304
Conversation
|
艹,竟然有人想起来这条issue |
|
你能给一个所有日志都被算为error的一个版本范围吗 |
|
update:上面评论所有的版本都解决了,可以随时审查合并 |
|
/gemini review |
There was a problem hiding this comment.
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.
|
/gemini review |
There was a problem hiding this comment.
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.
| 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); |
There was a problem hiding this comment.
在 LauncherHelper.java 中,如果 level 为 null,代码会再次调用 Log4jLevel.guessLevel(log)。然而,在第 937-939 行中,level 已经是通过 Log4jLevel.guessLevel 计算出来的。如果它为 null,再次调用也必然返回 null。
因此,这里可以直接使用 Log4jLevel.INFO 作为默认值,避免重复进行正则匹配,从而提高日志处理的效率。
| 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; |






update:下面评论所有的版本都解决了
Close #4240
老版本日志的级别都是本地化中文的,所以还需要根据这个判断日志级别,不能不改Log4jLevel.java,否则全部日志都会变成信息级别