List of usage examples for java.util.logging LogRecord setThrown
public void setThrown(Throwable thrown)
From source file:org.apache.tomee.util.SimpleTomEEFormatterTest.java
@Test public void formatNullThrown() throws Exception { final String previousLineSeparatorProperty = System.getProperty(LINE_SEPARATOR_KEY); try {//from w w w . jav a 2 s. c o m 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 StringBuilder expectedFormatOutputSb = new StringBuilder(level.getLocalizedName()); expectedFormatOutputSb.append(" - ").append(logMessage).append("\n"); final String expectedFormatOutput = expectedFormatOutputSb.toString(); assertEquals(expectedFormatOutput, actualFormatOutput); } finally { System.setProperty(LINE_SEPARATOR_KEY, previousLineSeparatorProperty); } }
From source file:org.apache.tomee.util.SimpleTomEEFormatterTest.java
@Test public void formatNotNullThrown() throws Exception { final String previousLineSeparatorProperty = System.getProperty(LINE_SEPARATOR_KEY); try {/*from w w w . ja v a 2 s. com*/ final String lineSeparatorValue = "\n"; final String logMessage = "An example log record"; final Level level = Level.CONFIG; final String exceptionMessage = "An example exception"; final Throwable thrown = new Exception(exceptionMessage); System.setProperty(LINE_SEPARATOR_KEY, lineSeparatorValue); final LogRecord logRecordInput = new LogRecord(level, logMessage); logRecordInput.setThrown(thrown); final Formatter formatter = new SimpleTomEEFormatter(); final String actualFormatOutput = formatter.format(logRecordInput); final StringBuilder expectedFormatOutputSb = new StringBuilder(level.getLocalizedName()); expectedFormatOutputSb.append(" - ").append(logMessage).append(lineSeparatorValue); expectedFormatOutputSb.append(ExceptionUtils.getStackTrace(thrown)); final String expectedFormatOutput = expectedFormatOutputSb.toString(); assertEquals(expectedFormatOutput, actualFormatOutput); } finally { System.setProperty(LINE_SEPARATOR_KEY, previousLineSeparatorProperty); } }
From source file:org.jretty.log.Jdk14Logger.java
/** * Log the message at the specified level with the specified throwable if any. This method creates a LogRecord and fills in caller date before calling this * instance's JDK14 logger./*w w w . j av a 2 s . c o m*/ */ private void log(String callerFQCN, Level level, String msg, Throwable t) { // millis and thread are filled by the constructor LogRecord record = new LogRecord(level, msg); record.setLoggerName(loggerName); record.setThrown(t); fillCallerData(callerFQCN, record); log.log(record); }