@Test public void formatNullThrown() throws Exception { final String previousLineSeparatorProperty = System.getProperty(LINE_SEPARATOR_KEY); try { final String lineSeparatorValue = "\n"; final String logMessage = "An example log record"; final Level level = Level.FINEST; System.setProperty(LINE_SEPARATOR_KEY, lineSeparatorValue); final LogRecord logRecordInput = new LogRecord(level, logMessage); logRecordInput.setThrown(null); final Formatter formatter = new SimpleTomEEFormatter(); final String actualFormatOutput = formatter.format(logRecordInput); final String expectedFormatOutput = level.getLocalizedName() + " - " + logMessage + "\n"; assertEquals(expectedFormatOutput, actualFormatOutput); } finally { System.setProperty(LINE_SEPARATOR_KEY, previousLineSeparatorProperty); } }
@SuppressWarnings("ThrowableResultOfMethodCallIgnored") @Override public synchronized String format(final LogRecord record) { final Throwable thrown = record.getThrown(); final StringBuilder sbuf = new StringBuilder(); sbuf.append(record.getLevel().getLocalizedName()); sbuf.append(" - "); sbuf.append(formatMessage(record)); sbuf.append(LN); if (thrown != null) { try { final StringWriter sw = new StringWriter(); final PrintWriter pw = new PrintWriter(sw); thrown.printStackTrace(pw); pw.close(); sbuf.append(sw.toString()); } catch (final Exception ex) { } } return sbuf.toString(); }
SimpleTomEEFormatter extends java.util.logging.Formatter { @SuppressWarnings("ThrowableResultOfMethodCallIgnored") @Override public synchronized String format(final LogRecord record) { final Throwable thrown = record.getThrown(); final StringBuilder sbuf = new StringBuilder(); sbuf.append(record.getLevel().getLocalizedName()); sbuf.append(" - "); sbuf.append(formatMessage(record)); sbuf.append(LN); if (thrown != null) { try { final StringWriter sw = new StringWriter(); final PrintWriter pw = new PrintWriter(sw); thrown.printStackTrace(pw); pw.close(); sbuf.append(sw.toString()); } catch (final Exception ex) { } } return sbuf.toString(); } }
SimpleTomEEFormatter extends java.util.logging.Formatter { @SuppressWarnings("ThrowableResultOfMethodCallIgnored") @Override public synchronized String format(final LogRecord record) { final Throwable thrown = record.getThrown(); final StringBuilder sbuf = new StringBuilder(); sbuf.append(record.getLevel().getLocalizedName()); sbuf.append(" - "); sbuf.append(formatMessage(record)); sbuf.append(LN); if (thrown != null) { try { final StringWriter sw = new StringWriter(); final PrintWriter pw = new PrintWriter(sw); thrown.printStackTrace(pw); pw.close(); sbuf.append(sw.toString()); } catch (final Exception ex) { } } return sbuf.toString(); }  }
SimpleTomEEFormatter extends java.util.logging.Formatter { @SuppressWarnings("ThrowableResultOfMethodCallIgnored") @Override public synchronized String format(final LogRecord record) { final Throwable thrown = record.getThrown(); final StringBuilder sbuf = new StringBuilder(); sbuf.append(record.getLevel().getLocalizedName()); sbuf.append(" - "); sbuf.append(formatMessage(record)); sbuf.append(LN); if (thrown != null) { try { final StringWriter sw = new StringWriter(); final PrintWriter pw = new PrintWriter(sw); thrown.printStackTrace(pw); pw.close(); sbuf.append(sw.toString()); } catch (final Exception ex) { } } return sbuf.toString(); }  @SuppressWarnings("ThrowableResultOfMethodCallIgnored") @Override synchronized String format(final LogRecord record); }
SimpleTomEEFormatter extends java.util.logging.Formatter { @SuppressWarnings("ThrowableResultOfMethodCallIgnored") @Override public synchronized String format(final LogRecord record) { final Throwable thrown = record.getThrown(); final StringBuilder sbuf = new StringBuilder(); sbuf.append(record.getLevel().getLocalizedName()); sbuf.append(" - "); sbuf.append(formatMessage(record)); sbuf.append(LN); if (thrown != null) { try { final StringWriter sw = new StringWriter(); final PrintWriter pw = new PrintWriter(sw); thrown.printStackTrace(pw); pw.close(); sbuf.append(sw.toString()); } catch (final Exception ex) { } } return sbuf.toString(); }  @SuppressWarnings("ThrowableResultOfMethodCallIgnored") @Override synchronized String format(final LogRecord record);  }