mirror of
https://github.com/HMCL-dev/HMCL.git
synced 2024-12-21 07:00:22 +08:00
导出更多日志 (#1970)
* close #1883: export vm crash log * fix #2047: export fml-client-latest.log
This commit is contained in:
parent
5d9d9b9cc4
commit
cf136fe7df
@ -19,17 +19,25 @@ package org.jackhuang.hmcl.game;
|
|||||||
|
|
||||||
import org.jackhuang.hmcl.util.Logging;
|
import org.jackhuang.hmcl.util.Logging;
|
||||||
import org.jackhuang.hmcl.util.StringUtils;
|
import org.jackhuang.hmcl.util.StringUtils;
|
||||||
|
import org.jackhuang.hmcl.util.io.FileUtils;
|
||||||
import org.jackhuang.hmcl.util.io.Zipper;
|
import org.jackhuang.hmcl.util.io.Zipper;
|
||||||
import org.jackhuang.hmcl.util.platform.OperatingSystem;
|
import org.jackhuang.hmcl.util.platform.OperatingSystem;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.UncheckedIOException;
|
import java.io.UncheckedIOException;
|
||||||
|
import java.lang.management.ManagementFactory;
|
||||||
|
import java.nio.file.DirectoryStream;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.attribute.BasicFileAttributes;
|
||||||
|
import java.nio.file.attribute.FileTime;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
|
import static org.jackhuang.hmcl.util.Logging.LOG;
|
||||||
|
|
||||||
public final class LogExporter {
|
public final class LogExporter {
|
||||||
private LogExporter() {
|
private LogExporter() {
|
||||||
@ -57,16 +65,37 @@ public final class LogExporter {
|
|||||||
|
|
||||||
return CompletableFuture.runAsync(() -> {
|
return CompletableFuture.runAsync(() -> {
|
||||||
try (Zipper zipper = new Zipper(zipFile)) {
|
try (Zipper zipper = new Zipper(zipFile)) {
|
||||||
if (Files.exists(runDirectory.resolve("logs").resolve("debug.log"))) {
|
Path logsDir = runDirectory.resolve("logs");
|
||||||
zipper.putFile(runDirectory.resolve("logs").resolve("debug.log"), "debug.log");
|
if (Files.exists(logsDir.resolve("debug.log"))) {
|
||||||
|
zipper.putFile(logsDir.resolve("debug.log"), "debug.log");
|
||||||
}
|
}
|
||||||
if (Files.exists(runDirectory.resolve("logs").resolve("latest.log"))) {
|
if (Files.exists(logsDir.resolve("latest.log"))) {
|
||||||
zipper.putFile(runDirectory.resolve("logs").resolve("latest.log"), "latest.log");
|
zipper.putFile(logsDir.resolve("latest.log"), "latest.log");
|
||||||
}
|
}
|
||||||
|
if (Files.exists(logsDir.resolve("fml-client-latest.log"))) {
|
||||||
|
zipper.putFile(logsDir.resolve("fml-client-latest.log"), "fml-client-latest.log");
|
||||||
|
}
|
||||||
|
|
||||||
zipper.putTextFile(Logging.getLogs(), "hmcl.log");
|
zipper.putTextFile(Logging.getLogs(), "hmcl.log");
|
||||||
zipper.putTextFile(logs, "minecraft.log");
|
zipper.putTextFile(logs, "minecraft.log");
|
||||||
zipper.putTextFile(Logging.filterForbiddenToken(launchScript), OperatingSystem.CURRENT_OS == OperatingSystem.WINDOWS ? "launch.bat" : "launch.sh");
|
zipper.putTextFile(Logging.filterForbiddenToken(launchScript), OperatingSystem.CURRENT_OS == OperatingSystem.WINDOWS ? "launch.bat" : "launch.sh");
|
||||||
|
|
||||||
|
try (DirectoryStream<Path> stream = Files.newDirectoryStream(runDirectory, "hs_err_*.log")) {
|
||||||
|
long processStartTime = ManagementFactory.getRuntimeMXBean().getStartTime();
|
||||||
|
|
||||||
|
for (Path file : stream) {
|
||||||
|
if (Files.isRegularFile(file)) {
|
||||||
|
FileTime time = Files.readAttributes(file, BasicFileAttributes.class).creationTime();
|
||||||
|
if (time.toMillis() >= processStartTime) {
|
||||||
|
String crashLog = Logging.filterForbiddenToken(FileUtils.readText(file));
|
||||||
|
zipper.putTextFile(crashLog, file.getFileName().toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Throwable e) {
|
||||||
|
LOG.log(Level.WARNING, "Failed to find vm crash log", e);
|
||||||
|
}
|
||||||
|
|
||||||
for (String id : versions) {
|
for (String id : versions) {
|
||||||
Path versionJson = baseDirectory.resolve("versions").resolve(id).resolve(id + ".json");
|
Path versionJson = baseDirectory.resolve("versions").resolve(id).resolve(id + ".json");
|
||||||
if (Files.exists(versionJson)) {
|
if (Files.exists(versionJson)) {
|
||||||
|
Loading…
Reference in New Issue
Block a user