diff --git a/pom.xml b/pom.xml index 0a12b7a..9664c96 100644 --- a/pom.xml +++ b/pom.xml @@ -39,9 +39,7 @@ ${project.basedir} false true - - MinecraftDecompiler.jar - + MinecraftDecompiler.jar diff --git a/src/main/java/cn/maxpixel/mcdecompiler/util/Logging.java b/src/main/java/cn/maxpixel/mcdecompiler/util/Logging.java index dfa8ff0..fb027f4 100644 --- a/src/main/java/cn/maxpixel/mcdecompiler/util/Logging.java +++ b/src/main/java/cn/maxpixel/mcdecompiler/util/Logging.java @@ -49,13 +49,8 @@ public final class Logging { PARENT = Logger.getLogger("cn.maxpixel.mcdecompiler"); PARENT.setUseParentHandlers(false); PARENT.setLevel(CONFIG.globalLevel); - StreamHandler handler = new StreamHandler(System.out, new LogFormatter()); + StdoutHandler handler = new StdoutHandler(); handler.setLevel(CONFIG.globalLevel); - try { - handler.setEncoding(StandardCharsets.UTF_8.name()); - } catch(UnsupportedEncodingException e) { - throw Utils.wrapInRuntime(e);// Shouldn't happen - } PARENT.addHandler(handler); } @@ -125,6 +120,44 @@ public static LogConfiguration fromInputStream(InputStream is) { } } + private static final class StdoutHandler extends Handler { + { + setFormatter(new LogFormatter()); + } + + private boolean doneHeader; + + @Override + public void publish(LogRecord record) { + if (!isLoggable(record)) return; + String msg; + try { + msg = getFormatter().format(record); + } catch (Exception ex) { + reportError(null, ex, ErrorManager.FORMAT_FAILURE); + return; + } + + try { + if (!doneHeader) { + System.out.print(getFormatter().getHead(this)); + doneHeader = true; + } + System.out.print(msg); + } catch (Exception ex) { + reportError(null, ex, ErrorManager.WRITE_FAILURE); + } + } + + @Override + public void flush() { + } + + @Override + public void close() throws SecurityException { + } + } + private static final class LogFormatter extends Formatter { private static final ZoneId zone = ZoneId.systemDefault(); @Override