Collect log when launcher crashed

This commit is contained in:
huangyuhui
2018-03-01 01:02:05 +08:00
parent 1bcef2bab0
commit eba0990538
2 changed files with 16 additions and 0 deletions

View File

@@ -111,6 +111,7 @@ public class CrashReporter implements Thread.UncaughtExceptionHandler {
HashMap<String, String> map = new HashMap<>();
map.put("crash_report", text);
map.put("version", Launcher.VERSION);
map.put("log", Logging.getLogs());
try {
String response = NetworkUtils.doPost(NetworkUtils.toURL("http://huangyuhui.duapp.com/hmcl/crash.php"), map);
if (StringUtils.isNotBlank(response))

View File

@@ -32,6 +32,7 @@ import java.util.logging.*;
public final class Logging {
public static final Logger LOG;
private static final ByteArrayOutputStream OUTPUT_STREAM = new ByteArrayOutputStream();
static {
LOG = Logger.getLogger("HMCL");
@@ -51,6 +52,20 @@ public final class Logging {
consoleHandler.setLevel(Level.FINER);
consoleHandler.setFormatter(DefaultFormatter.INSTANCE);
LOG.addHandler(consoleHandler);
StreamHandler streamHandler = new StreamHandler(OUTPUT_STREAM, DefaultFormatter.INSTANCE) {
@Override
public synchronized void publish(LogRecord record) {
super.publish(record);
flush();
}
};
streamHandler.setLevel(Level.FINEST);
LOG.addHandler(streamHandler);
}
public static String getLogs() {
return OUTPUT_STREAM.toString();
}
static final class DefaultFormatter extends Formatter {