[main] Split formatting for Throwable from formatter with message

This commit is contained in:
Johannes Frohnmeyer 2022-09-07 16:42:35 +02:00
parent 846766e3de
commit fb930b5979
Signed by: Johannes
GPG Key ID: E76429612C2929F4
1 changed files with 6 additions and 2 deletions

View File

@ -100,13 +100,17 @@ public interface Logger {
default String format(String msg, Throwable t) {
if (t == null) return msg;
return msg + System.lineSeparator() + format(t);
}
default String format(Throwable t) {
try (ByteArrayOutputStream baot = new ByteArrayOutputStream()) {
try (PrintStream ps = new PrintStream(baot, true)) {
t.printStackTrace(ps);
}
return msg + System.lineSeparator() + baot;
return baot.toString();
} catch (IOException e) {
return msg + System.lineSeparator() + t;
return t.toString();
}
}
}