mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-12 17:07:55 -04:00
Add Log::printException with minimum log level required
This commit is contained in:
parent
a0c39e835d
commit
ddd33e4132
@ -78,9 +78,7 @@ public class AssetsManager {
|
||||
try {
|
||||
downloadAssetsIndex();
|
||||
} catch (IOException e) {
|
||||
if (Log.getLevel().ordinal() >= LogLevels.DEBUG.ordinal()) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
Log.printException(e, LogLevels.DEBUG);
|
||||
Log.warn("Could not download assets index. Please check your internet connection");
|
||||
}
|
||||
assets.putAll(parseAssetsIndex(ASSETS_INDEX_HASH));
|
||||
|
@ -161,4 +161,17 @@ public class Log {
|
||||
public static void info(String message) {
|
||||
log(LogLevels.INFO, message, ChatColors.getColorByName("white"));
|
||||
}
|
||||
|
||||
public static boolean printException(Exception exception, LogLevels minimumLogLevel) {
|
||||
// ToDo: log to file, print also exceptions that are not printed with this method
|
||||
if (Log.getLevel().ordinal() >= minimumLogLevel.ordinal()) {
|
||||
exception.printStackTrace();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean printException(Exception exception) {
|
||||
return printException(exception, LogLevels.FATAL); // always print
|
||||
}
|
||||
}
|
||||
|
@ -158,9 +158,7 @@ public class Connection {
|
||||
try {
|
||||
Versions.loadVersionMappings(version.getVersionId());
|
||||
} catch (IOException e) {
|
||||
if (Log.getLevel().ordinal() >= LogLevels.DEBUG.ordinal()) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
Log.printException(e, LogLevels.DEBUG);
|
||||
Log.fatal(String.format("Could not load mapping for %s. This version seems to be unsupported!", version));
|
||||
lastException = new RuntimeException(String.format("Mappings could not be loaded: %s", e.getLocalizedMessage()));
|
||||
setConnectionState(ConnectionStates.FAILED_NO_RETRY);
|
||||
@ -223,9 +221,7 @@ public class Connection {
|
||||
}
|
||||
packet.handle(getHandler());
|
||||
} catch (Exception e) {
|
||||
if (Log.getLevel().ordinal() >= LogLevels.PROTOCOL.ordinal()) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
Log.printException(e, LogLevels.PROTOCOL);
|
||||
}
|
||||
}
|
||||
}, String.format("%d/Handling", connectionId));
|
||||
|
@ -233,18 +233,14 @@ public class SocketNetwork implements Network {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.printException(e, LogLevels.DEBUG);
|
||||
Log.protocol(String.format("An error occurred while parsing an packet (%s): %s", packet, e));
|
||||
if (Log.getLevel().ordinal() >= LogLevels.DEBUG.ordinal()) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
disconnect();
|
||||
} catch (IOException e) {
|
||||
// Could not connect
|
||||
if (Log.getLevel().ordinal() >= LogLevels.DEBUG.ordinal()) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
Log.printException(e, LogLevels.DEBUG);
|
||||
if (socketSThread != null) {
|
||||
socketSThread.interrupt();
|
||||
}
|
||||
|
@ -33,9 +33,7 @@ public final class HTTP {
|
||||
try {
|
||||
return client.send(request, HttpResponse.BodyHandlers.ofString());
|
||||
} catch (IOException | InterruptedException e) {
|
||||
if (Log.getLevel().ordinal() >= LogLevels.DEBUG.ordinal()) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
Log.printException(e, LogLevels.DEBUG);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user