void (@NotNull IdeScriptEngine engine) { final class Log extends Writer { private final boolean error; private Log(boolean error) { this.error = error; } @Override public void flush() { } @Override public void close() { } @Override public void write(char[] cbuf, int off, int len) { while (len > 0 && Character.isWhitespace(cbuf[off + len - 1])) len--; if (len == 0) return; String s = new String(cbuf, off, len); if (error) { LOG.warn(s); } else { LOG.info(s); } } } engine.setStdOut(new Log(false)); engine.setStdErr(new Log(true)); }