static void logWithJul(Level level, Object... messages) { Logger logger = Logger.getLogger("jline"); Throwable cause = null; ByteArrayOutputStream baos = new ByteArrayOutputStream(); PrintStream ps = new PrintStream(baos); for (int i = 0; i < messages.length; i++) { // Special handling for the last message if its a throwable, render its stack on the next line if (i + 1 == messages.length && messages[i] instanceof Throwable) { cause = (Throwable) messages[i]; } else { render(ps, messages[i]); } } ps.close(); LogRecord r = new LogRecord(toJulLevel(level), baos.toString()); r.setThrown(cause); logger.log(r); }
@TestAccessible static void log(final Level level, final Object... messages) { if (useJul) { logWithJul(level, messages); return; } //noinspection SynchronizeOnNonFinalField synchronized (output) { output.format("[%s] ", level); for (int i=0; i<messages.length; i++) { // Special handling for the last message if its a throwable, render its stack on the next line if (i + 1 == messages.length && messages[i] instanceof Throwable) { output.println(); ((Throwable)messages[i]).printStackTrace(output); } else { render(output, messages[i]); } } output.println(); output.flush(); } }
static void logWithJul(Level level, Object... messages) { Logger logger = Logger.getLogger("jline"); Throwable cause = null; ByteArrayOutputStream baos = new ByteArrayOutputStream(); PrintStream ps = new PrintStream(baos); for (int i = 0; i < messages.length; i++) { // Special handling for the last message if its a throwable, render its stack on the next line if (i + 1 == messages.length && messages[i] instanceof Throwable) { cause = (Throwable) messages[i]; } else { render(ps, messages[i]); } } ps.close(); LogRecord r = new LogRecord(toJulLevel(level), baos.toString()); r.setThrown(cause); logger.log(r); }
@TestAccessible static void log(final Level level, final Object... messages) { if (useJul) { logWithJul(level, messages); return; } //noinspection SynchronizeOnNonFinalField synchronized (output) { output.format("[%s] ", level); for (int i=0; i<messages.length; i++) { // Special handling for the last message if its a throwable, render its stack on the next line if (i + 1 == messages.length && messages[i] instanceof Throwable) { output.println(); ((Throwable)messages[i]).printStackTrace(output); } else { render(output, messages[i]); } } output.println(); output.flush(); } }