| 21 | import packetproxy.gui.GUILog; |
| 22 | |
| 23 | public class Logging { |
| 24 | |
| 25 | private static final DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm:ss"); |
| 26 | private static final GUILog guiLog = GUILog.getInstance(); |
| 27 | |
| 28 | private Logging() { |
| 29 | } |
| 30 | |
| 31 | public static void log(String format, Object... args) throws IllegalFormatException { |
| 32 | LocalDateTime now = LocalDateTime.now(); |
| 33 | String ns = dtf.format(now); |
| 34 | String ss = ns + " " + String.format(format, args); |
| 35 | System.out.println(ss); |
| 36 | guiLog.append(ss); |
| 37 | } |
| 38 | |
| 39 | public static void err(String format, Object... args) throws IllegalFormatException { |
| 40 | LocalDateTime now = LocalDateTime.now(); |
| 41 | String ns = dtf.format(now); |
| 42 | String ss = ns + " " + String.format(format, args); |
| 43 | System.err.println(ss); |
| 44 | guiLog.appendErr(ss); |
| 45 | } |
| 46 | |
| 47 | public static void errWithStackTrace(Throwable e) throws IllegalFormatException { |
| 48 | err(e.toString()); |
| 49 | StackTraceElement[] stackTrace = e.getStackTrace(); |
| 50 | for (var element : stackTrace) { |
| 51 | err(element.toString()); |
| 52 | } |
| 53 | } |
| 54 | } |
nothing calls this directly
no test coverage detected