Skip to content

Commit 6935728

Browse files
committed
feat: 允许输出调试日志
1 parent 69f3542 commit 6935728

File tree

10 files changed

+127
-109
lines changed

10 files changed

+127
-109
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Configuration status="warn" packages="">
3+
<Appenders>
4+
<Console name="SysOut" target="SYSTEM_OUT">
5+
<PatternLayout pattern="[%d{HH:mm:ss}] [%t/%level]: %msg{nolookups}%n" />
6+
</Console>
7+
<Queue name="ServerGuiConsole">
8+
<PatternLayout pattern="[%d{HH:mm:ss} %level]: %msg{nolookups}%n" />
9+
</Queue>
10+
<RollingRandomAccessFile name="File" fileName="logs/latest.log" filePattern="logs/%d{yyyy-MM-dd}-%i.log.gz">
11+
<PatternLayout pattern="[%d{HH:mm:ss}] [%t/%level] [%logger]: %msg{nolookups}%n"/>
12+
<Policies>
13+
<TimeBasedTriggeringPolicy/>
14+
<OnStartupTriggeringPolicy/>
15+
</Policies>
16+
</RollingRandomAccessFile>
17+
<RollingRandomAccessFile name="DebugFile" fileName="logs/debug.log" filePattern="logs/debug-%d{yyyy-MM-dd}-%i.log.gz">
18+
<PatternLayout pattern="[%d{yyyy-MM-dd HH:mm:ss}] [%t/%level] [%logger]: %msg{nolookups}%n"/>
19+
<Policies>
20+
<TimeBasedTriggeringPolicy/>
21+
<OnStartupTriggeringPolicy/>
22+
</Policies>
23+
<DefaultRolloverStrategy max="999" fileIndex="min"/>
24+
</RollingRandomAccessFile>
25+
</Appenders>
26+
<Loggers>
27+
<Root level="all">
28+
<filters>
29+
<MarkerFilter marker="NETWORK_PACKETS" onMatch="DENY" onMismatch="NEUTRAL"/>
30+
</filters>
31+
<AppenderRef ref="SysOut" level="info"/>
32+
<AppenderRef ref="ServerGuiConsole" level="info"/>
33+
<AppenderRef ref="File" level="info"/>
34+
<AppenderRef ref="DebugFile" level="all"/>
35+
</Root>
36+
</Loggers>
37+
</Configuration>
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Configuration status="WARN">
3+
<Appenders>
4+
<Console name="SysOut" target="SYSTEM_OUT">
5+
<PatternLayout pattern="[%d{HH:mm:ss}] [%t/%level]: %msg%n" />
6+
</Console>
7+
<Queue name="ServerGuiConsole">
8+
<PatternLayout pattern="[%d{HH:mm:ss} %level]: %msg%n" />
9+
</Queue>
10+
<RollingRandomAccessFile name="File" fileName="logs/latest.log" filePattern="logs/%d{yyyy-MM-dd}-%i.log.gz">
11+
<PatternLayout pattern="[%d{HH:mm:ss}] [%t/%level] [%logger]: %msg%n"/>
12+
<Policies>
13+
<TimeBasedTriggeringPolicy/>
14+
<OnStartupTriggeringPolicy/>
15+
</Policies>
16+
</RollingRandomAccessFile>
17+
<RollingRandomAccessFile name="DebugFile" fileName="logs/debug.log" filePattern="logs/debug-%d{yyyy-MM-dd}-%i.log.gz">
18+
<PatternLayout pattern="[%d{yyyy-MM-dd HH:mm:ss}] [%t/%level] [%logger]: %msg%n"/>
19+
<Policies>
20+
<TimeBasedTriggeringPolicy/>
21+
<OnStartupTriggeringPolicy/>
22+
</Policies>
23+
</RollingRandomAccessFile>
24+
</Appenders>
25+
<Loggers>
26+
<Root level="all">
27+
<filters>
28+
<MarkerFilter marker="NETWORK_PACKETS" onMatch="DENY" onMismatch="NEUTRAL"/>
29+
</filters>
30+
<AppenderRef ref="SysOut" level="info"/>
31+
<AppenderRef ref="ServerGuiConsole" level="info"/>
32+
<AppenderRef ref="File" level="info"/>
33+
<AppenderRef ref="DebugFile" level="all"/>
34+
</Root>
35+
</Loggers>
36+
</Configuration>

FCL/src/main/java/com/tungsten/fcl/game/FCLGameRepository.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,8 @@ public LaunchOptions getLaunchOptions(String version, JavaVersion javaVersion, F
360360
.setBEGesture(vs.isBeGesture())
361361
.setVkDriverSystem(vs.isVKDriverSystem())
362362
.setPojavBigCore(vs.isPojavBigCore())
363-
.setRenderer(RendererManager.getRenderer(vs.getRenderer()));
363+
.setRenderer(RendererManager.getRenderer(vs.getRenderer()))
364+
.setDebugLog(vs.isDebugLog());
364365

365366
File json = getModpackConfiguration(version);
366367
if (json.exists()) {

FCL/src/main/java/com/tungsten/fcl/setting/VersionSetting.kt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,13 @@ class VersionSetting : Cloneable {
239239
notCheckModProperty.set(value)
240240
}
241241

242+
var debugLogProperty: BooleanProperty = SimpleBooleanProperty(this, "debugLog", false)
243+
var isDebugLog: Boolean
244+
get() = debugLogProperty.get()
245+
set(value) {
246+
debugLogProperty.set(value)
247+
}
248+
242249
fun checkController() {
243250
Controllers.addCallback {
244251
Controllers.checkControllers()
@@ -271,6 +278,7 @@ class VersionSetting : Cloneable {
271278
pojavBigCoreProperty.addListener(listener)
272279
uuidProperty.addListener(listener)
273280
notCheckModProperty.addListener(listener)
281+
debugLogProperty.addListener(listener)
274282
}
275283

276284
public override fun clone(): VersionSetting {
@@ -295,6 +303,7 @@ class VersionSetting : Cloneable {
295303
it.isPojavBigCore = isPojavBigCore
296304
it.uuid = uuid
297305
it.isNotCheckMod = isNotCheckMod
306+
it.isDebugLog = isDebugLog
298307
}
299308
}
300309

@@ -329,6 +338,7 @@ class VersionSetting : Cloneable {
329338
addProperty("pojavBigCore", src.isPojavBigCore)
330339
addProperty("uuid", src.uuid)
331340
addProperty("notCheckMod", src.isNotCheckMod)
341+
addProperty("debugLog", src.isDebugLog)
332342
}
333343
}
334344

@@ -369,6 +379,7 @@ class VersionSetting : Cloneable {
369379
vs.isPojavBigCore = json["pojavBigCore"]?.asBoolean ?: false
370380
vs.uuid = json["uuid"]?.asString ?: ""
371381
vs.isNotCheckMod = json["notCheckMod"]?.asBoolean ?: false
382+
vs.isDebugLog = json["debugLog"]?.asBoolean ?: false
372383
}
373384
}
374385

FCL/src/main/java/com/tungsten/fcl/ui/manage/VersionSettingPage.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ public class VersionSettingPage extends FCLCommonPage implements ManageUI.Versio
9494
private FCLSwitch noGameCheckSwitch;
9595
private FCLSwitch noJVMCheckSwitch;
9696
private FCLSwitch noModCheckSwitch;
97+
private FCLSwitch debugLogSwitch;
9798

9899
private FCLImageButton javaButton;
99100
private FCLImageButton javaInstallButton;
@@ -150,6 +151,7 @@ private void create() {
150151
noGameCheckSwitch = findViewById(R.id.edit_not_check_game);
151152
noJVMCheckSwitch = findViewById(R.id.edit_not_check_java);
152153
noModCheckSwitch = findViewById(R.id.not_check_mod);
154+
debugLogSwitch = findViewById(R.id.debug_log);
153155

154156
isolateWorkingDirSwitch.disableProperty().bind(modpack);
155157
scaleFactorSeekbar.addProgressListener();
@@ -294,6 +296,7 @@ public void loadVersion(Profile profile, String versionId) {
294296
FXUtils.unbindBoolean(noGameCheckSwitch, lastVersionSetting.getNotCheckGameProperty());
295297
FXUtils.unbindBoolean(noJVMCheckSwitch, lastVersionSetting.getNotCheckJVMProperty());
296298
FXUtils.unbindBoolean(noModCheckSwitch, lastVersionSetting.getNotCheckModProperty());
299+
FXUtils.unbindBoolean(debugLogSwitch, lastVersionSetting.getDebugLogProperty());
297300
FXUtils.unbindBoolean(beGestureSwitch, lastVersionSetting.getBeGestureProperty());
298301
FXUtils.unbindBoolean(vulkanDriverSystemSwitch, lastVersionSetting.getVkDriverSystemProperty());
299302
scaleFactorSeekbar.progressProperty().unbindBidirectional(lastVersionSetting.getScaleFactorProperty());
@@ -316,6 +319,7 @@ public void loadVersion(Profile profile, String versionId) {
316319
FXUtils.bindBoolean(noGameCheckSwitch, versionSetting.getNotCheckGameProperty());
317320
FXUtils.bindBoolean(noJVMCheckSwitch, versionSetting.getNotCheckJVMProperty());
318321
FXUtils.bindBoolean(noModCheckSwitch, versionSetting.getNotCheckModProperty());
322+
FXUtils.bindBoolean(debugLogSwitch, versionSetting.getDebugLogProperty());
319323
FXUtils.bindBoolean(beGestureSwitch, versionSetting.getBeGestureProperty());
320324
FXUtils.bindBoolean(vulkanDriverSystemSwitch, versionSetting.getVkDriverSystemProperty());
321325
scaleFactorSeekbar.progressProperty().bindBidirectional(versionSetting.getScaleFactorProperty());

FCL/src/main/res/layout/page_version_setting.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,18 @@
578578
android:layout_height="1dp"
579579
android:background="@android:color/darker_gray" />
580580

581+
<com.tungsten.fcllibrary.component.view.FCLSwitch
582+
android:id="@+id/debug_log"
583+
android:layout_width="match_parent"
584+
android:layout_height="wrap_content"
585+
android:layout_gravity="center"
586+
android:text="@string/settings_advanced_debug_log" />
587+
588+
<View
589+
android:layout_width="match_parent"
590+
android:layout_height="1dp"
591+
android:background="@android:color/darker_gray" />
592+
581593
<androidx.appcompat.widget.LinearLayoutCompat
582594
android:layout_width="match_parent"
583595
android:layout_height="wrap_content"

FCL/src/main/res/values-zh/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -781,6 +781,7 @@
781781
<string name="settings_advanced_dont_check_game_completeness">不检查游戏完整性</string>
782782
<string name="settings_advanced_dont_check_jvm_validity">不检查 JVM 兼容性</string>
783783
<string name="settings_advanced_dont_check_mod">不检查模组兼容性</string>
784+
<string name="settings_advanced_debug_log">输出调试日志</string>
784785
<string name="settings_advanced_game_dir_default">默认 (.minecraft/)</string>
785786
<string name="settings_advanced_game_dir_independent">各版本独立 (存放在 .minecraft/versions/&#60;版本名>/,除 assets、libraries 外)</string>
786787
<string name="settings_advanced_jvm_args">Java 虚拟机参数</string>

FCL/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -828,6 +828,7 @@
828828
<string name="settings_advanced_dont_check_game_completeness">Do not check game integrity</string>
829829
<string name="settings_advanced_dont_check_jvm_validity">Do not check JVM compatibility</string>
830830
<string name="settings_advanced_dont_check_mod">Do not check Mod compatibility</string>
831+
<string name="settings_advanced_debug_log">Output debug log</string>
831832
<string name="settings_advanced_game_dir_default">Default (.minecraft/)</string>
832833
<string name="settings_advanced_game_dir_independent">Isolated (.minecraft/versions/&#60;instance name>/, except for assets and libraries)</string>
833834
<string name="settings_advanced_jvm_args">Java VM arguments</string>

FCLCore/src/main/java/com/tungsten/fclcore/game/LaunchOptions.java

Lines changed: 10 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ public class LaunchOptions implements Serializable {
4848
private boolean pojavBigCore;
4949
private Renderer renderer;
5050
private String uuid;
51+
private boolean debugLog;
5152

5253
/**
5354
* The game directory
@@ -179,6 +180,10 @@ public String getUuid() {
179180
return uuid;
180181
}
181182

183+
public boolean isDebugLog() {
184+
return debugLog;
185+
}
186+
182187
public static class Builder {
183188

184189
private final LaunchOptions options = new LaunchOptions();
@@ -187,123 +192,20 @@ public LaunchOptions create() {
187192
return options;
188193
}
189194

190-
/**
191-
* The game directory
192-
*/
193-
public File getGameDir() {
194-
return options.gameDir;
195-
}
196-
197-
/**
198-
* The Java Environment that Minecraft runs on.
199-
*/
200-
public JavaVersion getJava() {
201-
return options.java;
202-
}
203-
204-
/**
205-
* Will shown in the left bottom corner of the main menu of Minecraft.
206-
* null if use the id of launch version.
207-
*/
208-
public String getVersionName() {
209-
return options.versionName;
210-
}
211-
212-
/**
213-
* Will shown in the left bottom corner of the main menu of Minecraft.
214-
* null if use Version.versionType.
215-
*/
216-
public String getVersionType() {
217-
return options.versionType;
218-
}
219-
220-
/**
221-
* Don't know what the hell this is.
222-
*/
223-
public String getProfileName() {
224-
return options.profileName;
225-
}
226-
227195
/**
228196
* User custom additional minecraft command line arguments.
229197
*/
230198
public List<String> getGameArguments() {
231199
return options.gameArguments;
232200
}
233201

234-
/**
235-
* The highest priority JVM arguments (overrides the version setting)
236-
*/
237-
public List<String> getOverrideJavaArguments() {
238-
return options.overrideJavaArguments;
239-
}
240-
241202
/**
242203
* User custom additional java virtual machine command line arguments.
243204
*/
244205
public List<String> getJavaArguments() {
245206
return options.javaArguments;
246207
}
247208

248-
public List<String> getJavaAgents() {
249-
return options.javaAgents;
250-
}
251-
252-
/**
253-
* The minimum memory that the JVM can allocate.
254-
*/
255-
public Integer getMinMemory() {
256-
return options.minMemory;
257-
}
258-
259-
/**
260-
* The maximum memory that the JVM can allocate.
261-
*/
262-
public Integer getMaxMemory() {
263-
return options.maxMemory;
264-
}
265-
266-
/**
267-
* The initial game window width
268-
*/
269-
public Integer getWidth() {
270-
return options.width;
271-
}
272-
273-
/**
274-
* The initial game window height
275-
*/
276-
public Integer getHeight() {
277-
return options.height;
278-
}
279-
280-
/**
281-
* The server ip that will connect to when enter game main menu.
282-
*/
283-
public String getServerIp() {
284-
return options.serverIp;
285-
}
286-
287-
/**
288-
* BE Gesture
289-
*/
290-
public boolean isBeGesture() {
291-
return options.beGesture;
292-
}
293-
294-
/**
295-
* vulkanDriverSystem
296-
*/
297-
public boolean isVKDriverSystem() {
298-
return options.vulkanDriverSystem;
299-
}
300-
301-
/**
302-
* Renderer
303-
*/
304-
public Renderer getRenderer() {
305-
return options.renderer;
306-
}
307209

308210
public Builder setGameDir(File gameDir) {
309211
options.gameDir = gameDir;
@@ -404,5 +306,10 @@ public Builder setUUid(String uuid) {
404306
return this;
405307
}
406308

309+
public Builder setDebugLog(boolean debugLog) {
310+
options.debugLog = debugLog;
311+
return this;
312+
}
313+
407314
}
408315
}

FCLCore/src/main/java/com/tungsten/fclcore/launch/DefaultLauncher.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ private CommandBuilder generateCommandLine() throws IOException {
117117
res.addDefault("-Dcom.sun.jndi.cosnaming.object.trustURLCodebase=", "false");
118118

119119
String formatMsgNoLookups = res.addDefault("-Dlog4j2.formatMsgNoLookups=", "true");
120-
if (!"-Dlog4j2.formatMsgNoLookups=false".equals(formatMsgNoLookups) && isUsingLog4j()) {
120+
if (isUsingLog4j() && (options.isDebugLog() || !"-Dlog4j2.formatMsgNoLookups=false".equals(formatMsgNoLookups))) {
121121
res.addDefault("-Dlog4j.configurationFile=", getLog4jConfigurationFile().getAbsolutePath());
122122
}
123123

@@ -412,12 +412,20 @@ public File getLog4jConfigurationFile() {
412412

413413
public void extractLog4jConfigurationFile() throws IOException {
414414
File targetFile = getLog4jConfigurationFile();
415-
if (targetFile.exists()) return;
416415
InputStream source;
417-
if (GameVersionNumber.compare(repository.getGameVersion(version).orElse("0.0"), "1.12") < 0) {
418-
source = DefaultLauncher.class.getResourceAsStream("/assets/game/log4j2-1.7.xml");
416+
417+
if (GameVersionNumber.asGameVersion(repository.getGameVersion(version)).compareTo("1.12") < 0) {
418+
if (options.isDebugLog()) {
419+
source = DefaultLauncher.class.getResourceAsStream("/assets/game/log4j2-1.7-debug.xml");
420+
} else {
421+
source = DefaultLauncher.class.getResourceAsStream("/assets/game/log4j2-1.7.xml");
422+
}
419423
} else {
420-
source = DefaultLauncher.class.getResourceAsStream("/assets/game/log4j2-1.12.xml");
424+
if (options.isDebugLog()) {
425+
source = DefaultLauncher.class.getResourceAsStream("/assets/game/log4j2-1.12-debug.xml");
426+
} else {
427+
source = DefaultLauncher.class.getResourceAsStream("/assets/game/log4j2-1.12.xml");
428+
}
421429
}
422430

423431
try (InputStream input = source; OutputStream output = new FileOutputStream(targetFile)) {

0 commit comments

Comments
 (0)