Example usage for java.util.logging LogRecord getThrown

List of usage examples for java.util.logging LogRecord getThrown

Introduction

In this page you can find the example usage for java.util.logging LogRecord getThrown.

Prototype

public Throwable getThrown() 

Source Link

Document

Get any throwable associated with the log record.

Usage

From source file:com.gemstone.gemfire.management.internal.cli.shell.GfshInitFileJUnitTest.java

@Test
public void testInitFile_NotFound() throws Exception {
    // Construct the file name but not the file
    String initFileName = temporaryFolder_CurrentDirectory.getRoot().getAbsolutePath() + File.separator
            + INIT_FILE_NAME;/*from ww  w. j av  a 2  s  .co  m*/

    /*
     * String historyFileName, String defaultPrompt, int historySize, String
     * logDir, Level logLevel, Integer logLimit, Integer logCount, String
     * initFileName
     */
    GfshConfig gfshConfig = new GfshConfig(this.gfshHistoryFileName, "", 0,
            temporaryFolder_CurrentDirectory.getRoot().getAbsolutePath(), null, null, null, initFileName);
    assertNotNull(INIT_FILE_NAME, gfshConfig.getInitFileName());

    /*
     * boolean launchShell, String[] args, GfshConfig gfshConfig
     */
    Gfsh gfsh = Gfsh.getInstance(false, new String[] {}, gfshConfig);

    int actualStatus = gfsh.getLastExecutionStatus();
    int expectedStatus = 0;
    assertNotEquals("Status <0==failure", expectedStatus, actualStatus);

    int expectedLogCount = BANNER_LINES + INIT_FILE_CITATION_LINES + 1;
    assertEquals("Log records written", expectedLogCount, this.junitLoggerHandler.getLog().size());
    Throwable exception = null;
    for (LogRecord logRecord : this.junitLoggerHandler.getLog()) {
        if (logRecord.getThrown() != null) {
            exception = logRecord.getThrown();
            break;
        }
    }
    assertNotNull("Exceptions in log", exception);
}

From source file:com.gemstone.gemfire.management.internal.cli.shell.GfshInitFileJUnitTest.java

@Test
public void testInitFile_NotProvided() throws Exception {
    /*// w w  w  .ja va 2  s.  c o  m
     * String historyFileName, String defaultPrompt, int historySize, String
     * logDir, Level logLevel, Integer logLimit, Integer logCount, String
     * initFileName
     */
    GfshConfig gfshConfig = new GfshConfig(this.gfshHistoryFileName, "", 0,
            temporaryFolder_CurrentDirectory.getRoot().getAbsolutePath(), null, null, null, null);
    assertNull(INIT_FILE_NAME, gfshConfig.getInitFileName());

    /*
     * boolean launchShell, String[] args, GfshConfig gfshConfig
     */
    Gfsh gfsh = Gfsh.getInstance(false, new String[] {}, gfshConfig);

    int actualStatus = gfsh.getLastExecutionStatus();
    int expectedStatus = 0;
    assertEquals("Status 0==success", expectedStatus, actualStatus);

    int expectedLogCount = BANNER_LINES;
    assertEquals("Log records written", expectedLogCount, this.junitLoggerHandler.getLog().size());
    for (LogRecord logRecord : this.junitLoggerHandler.getLog()) {
        assertNull("No exceptions in log", logRecord.getThrown());
    }
}

From source file:net.officefloor.plugin.woof.servlet.container.ServletContainerWoofApplicationExtensionServiceTest.java

/**
 * Ensure {@link Servlet} container is not loaded for marker
 * <code>web.xml</code>.// w w  w.j a  va  2s .  co m
 */
public void testNotLoadServletContainerForMarkerFile() throws Exception {

    // Ensure log invalid web.xml
    LoggerAssertion log = LoggerAssertion
            .setupLoggerAssertion(ServletContainerWoofApplicationExtensionService.class.getName());
    try {

        // Test
        this.startServer("src/test/invalid-webapp", "invalid-application.woof");
        String responseText = this.doGetEntity("/servlet.html");
        assertEquals("Should be resource as servlet container not loaded for marker web.xml",
                "NOT HTTP_SERVLET", responseText);

    } finally {
        // Validate log records
        LogRecord[] records = log.disconnectFromLogger();
        assertEquals("Incorrect number of log reords", 1, records.length);
        LogRecord record = records[0];
        String cause = "Invalid web.xml configuration [XmlMarshallException]: Content is not allowed in prolog.";
        assertEquals("Incorrect log message",
                "Invalid WEB-INF/web.xml so not loading Servlet servicers: " + cause, record.getMessage());
        assertNull("Should not be cause as contained in message", record.getThrown());
    }
}

From source file:com.gemstone.gemfire.management.internal.cli.shell.GfshInitFileJUnitTest.java

@Test
public void testInitFile_Empty() throws Exception {
    File initFile = temporaryFolder_CurrentDirectory.newFile(INIT_FILE_NAME);

    /*//  w ww  .  j av  a2s.  c  o m
     * String historyFileName, String defaultPrompt, int historySize, String
     * logDir, Level logLevel, Integer logLimit, Integer logCount, String
     * initFileName
     */
    GfshConfig gfshConfig = new GfshConfig(this.gfshHistoryFileName, "", 0,
            temporaryFolder_CurrentDirectory.getRoot().getAbsolutePath(), null, null, null,
            initFile.getAbsolutePath());
    assertNotNull(INIT_FILE_NAME, gfshConfig.getInitFileName());

    /*
     * boolean launchShell, String[] args, GfshConfig gfshConfig
     */
    Gfsh gfsh = Gfsh.getInstance(false, new String[] {}, gfshConfig);

    int actualStatus = gfsh.getLastExecutionStatus();
    int expectedStatus = 0;
    assertEquals("Status 0==success", expectedStatus, actualStatus);

    int expectedLogCount = BANNER_LINES + INIT_FILE_CITATION_LINES + 1;
    assertEquals("Log records written", expectedLogCount, this.junitLoggerHandler.getLog().size());
    for (LogRecord logRecord : this.junitLoggerHandler.getLog()) {
        assertNull("No exceptions in log", logRecord.getThrown());
    }
}

From source file:com.gemstone.gemfire.management.internal.cli.shell.GfshInitFileJUnitTest.java

@Test
public void testInitFile_OneGoodCommand() throws Exception {
    File initFile = temporaryFolder_CurrentDirectory.newFile(INIT_FILE_NAME);
    FileUtils.writeStringToFile(initFile, "echo --string=hello" + Gfsh.LINE_SEPARATOR, APPEND);

    /*/*from  www.jav a2  s .  co  m*/
     * String historyFileName, String defaultPrompt, int historySize, String
     * logDir, Level logLevel, Integer logLimit, Integer logCount, String
     * initFileName
     */
    GfshConfig gfshConfig = new GfshConfig(this.gfshHistoryFileName, "", 0,
            temporaryFolder_CurrentDirectory.getRoot().getAbsolutePath(), null, null, null,
            initFile.getAbsolutePath());
    assertNotNull(INIT_FILE_NAME, gfshConfig.getInitFileName());

    /*
     * boolean launchShell, String[] args, GfshConfig gfshConfig
     */
    Gfsh gfsh = Gfsh.getInstance(false, new String[] {}, gfshConfig);

    int actualStatus = gfsh.getLastExecutionStatus();
    int expectedStatus = 0;
    assertEquals("Status 0==success", expectedStatus, actualStatus);

    int expectedLogCount = BANNER_LINES + INIT_FILE_CITATION_LINES + 1;
    assertEquals("Log records written", expectedLogCount, this.junitLoggerHandler.getLog().size());
    for (LogRecord logRecord : this.junitLoggerHandler.getLog()) {
        assertNull("No exceptions in log", logRecord.getThrown());
    }
}

From source file:com.gemstone.gemfire.management.internal.cli.shell.GfshInitFileJUnitTest.java

@Test
public void testInitFile_OneBadCommand() throws Exception {
    File initFile = temporaryFolder_CurrentDirectory.newFile(INIT_FILE_NAME);
    FileUtils.writeStringToFile(initFile, "fail" + Gfsh.LINE_SEPARATOR, APPEND);

    /*// ww w.  j ava2 s .c o  m
     * String historyFileName, String defaultPrompt, int historySize, String
     * logDir, Level logLevel, Integer logLimit, Integer logCount, String
     * initFileName
     */
    GfshConfig gfshConfig = new GfshConfig(this.gfshHistoryFileName, "", 0,
            temporaryFolder_CurrentDirectory.getRoot().getAbsolutePath(), null, null, null,
            initFile.getAbsolutePath());
    assertNotNull(INIT_FILE_NAME, gfshConfig.getInitFileName());

    /*
     * boolean launchShell, String[] args, GfshConfig gfshConfig
     */
    Gfsh gfsh = Gfsh.getInstance(false, new String[] {}, gfshConfig);

    int actualStatus = gfsh.getLastExecutionStatus();
    int expectedStatus = 0;
    assertNotEquals("Status <0==failure", expectedStatus, actualStatus);

    int expectedLogCount = BANNER_LINES + INIT_FILE_CITATION_LINES + 1;
    assertEquals("Log records written", expectedLogCount, this.junitLoggerHandler.getLog().size());
    for (LogRecord logRecord : this.junitLoggerHandler.getLog()) {
        assertNull("No exceptions in log", logRecord.getThrown());
    }
}

From source file:com.gemstone.gemfire.management.internal.cli.shell.GfshInitFileJUnitTest.java

@Test
public void testInitFile_TwoGoodCommands() throws Exception {
    File initFile = temporaryFolder_CurrentDirectory.newFile(INIT_FILE_NAME);
    FileUtils.writeStringToFile(initFile, "echo --string=hello" + Gfsh.LINE_SEPARATOR, APPEND);
    FileUtils.writeStringToFile(initFile, "echo --string=goodbye" + Gfsh.LINE_SEPARATOR, APPEND);

    /*/*from  w  w w.  jav a 2 s  .c o  m*/
     * String historyFileName, String defaultPrompt, int historySize, String
     * logDir, Level logLevel, Integer logLimit, Integer logCount, String
     * initFileName
     */
    GfshConfig gfshConfig = new GfshConfig(this.gfshHistoryFileName, "", 0,
            temporaryFolder_CurrentDirectory.getRoot().getAbsolutePath(), null, null, null,
            initFile.getAbsolutePath());
    assertNotNull(INIT_FILE_NAME, gfshConfig.getInitFileName());

    /*
     * boolean launchShell, String[] args, GfshConfig gfshConfig
     */
    Gfsh gfsh = Gfsh.getInstance(false, new String[] {}, gfshConfig);

    int actualStatus = gfsh.getLastExecutionStatus();
    int expectedStatus = 0;
    assertEquals("Status 0==success", expectedStatus, actualStatus);

    int expectedLogCount = BANNER_LINES + INIT_FILE_CITATION_LINES + 1;
    assertEquals("Log records written", expectedLogCount, this.junitLoggerHandler.getLog().size());
    for (LogRecord logRecord : this.junitLoggerHandler.getLog()) {
        assertNull("No exceptions in log", logRecord.getThrown());
    }
}

From source file:com.gemstone.gemfire.management.internal.cli.shell.GfshInitFileJUnitTest.java

@Test
public void testInitFile_TwoBadCommands() throws Exception {
    File initFile = temporaryFolder_CurrentDirectory.newFile(INIT_FILE_NAME);
    FileUtils.writeStringToFile(initFile, "fail" + Gfsh.LINE_SEPARATOR, APPEND);
    FileUtils.writeStringToFile(initFile, "fail" + Gfsh.LINE_SEPARATOR, APPEND);

    /*/*from www.jav a 2 s .  c  om*/
     * String historyFileName, String defaultPrompt, int historySize, String
     * logDir, Level logLevel, Integer logLimit, Integer logCount, String
     * initFileName
     */
    GfshConfig gfshConfig = new GfshConfig(this.gfshHistoryFileName, "", 0,
            temporaryFolder_CurrentDirectory.getRoot().getAbsolutePath(), null, null, null,
            initFile.getAbsolutePath());
    assertNotNull(INIT_FILE_NAME, gfshConfig.getInitFileName());

    /*
     * boolean launchShell, String[] args, GfshConfig gfshConfig
     */
    Gfsh gfsh = Gfsh.getInstance(false, new String[] {}, gfshConfig);

    int actualStatus = gfsh.getLastExecutionStatus();
    int expectedStatus = 0;
    assertNotEquals("Status <0==failure", expectedStatus, actualStatus);

    int expectedLogCount = BANNER_LINES + INIT_FILE_CITATION_LINES + 1;
    assertEquals("Log records written", expectedLogCount, this.junitLoggerHandler.getLog().size());
    for (LogRecord logRecord : this.junitLoggerHandler.getLog()) {
        assertNull("No exceptions in log", logRecord.getThrown());
    }
}

From source file:com.gemstone.gemfire.management.internal.cli.shell.GfshInitFileJUnitTest.java

@Test
public void testInitFile_BadAndGoodCommands() throws Exception {
    File initFile = temporaryFolder_CurrentDirectory.newFile(INIT_FILE_NAME);
    FileUtils.writeStringToFile(initFile, "fail" + Gfsh.LINE_SEPARATOR, APPEND);
    FileUtils.writeStringToFile(initFile, "echo --string=goodbye" + Gfsh.LINE_SEPARATOR, APPEND);

    /*/*from w  ww  .  ja  va  2s  .c o m*/
     * String historyFileName, String defaultPrompt, int historySize, String
     * logDir, Level logLevel, Integer logLimit, Integer logCount, String
     * initFileName
     */
    GfshConfig gfshConfig = new GfshConfig(this.gfshHistoryFileName, "", 0,
            temporaryFolder_CurrentDirectory.getRoot().getAbsolutePath(), null, null, null,
            initFile.getAbsolutePath());
    assertNotNull(INIT_FILE_NAME, gfshConfig.getInitFileName());

    /*
     * boolean launchShell, String[] args, GfshConfig gfshConfig
     */
    Gfsh gfsh = Gfsh.getInstance(false, new String[] {}, gfshConfig);

    int actualStatus = gfsh.getLastExecutionStatus();
    int expectedStatus = 0;
    assertNotEquals("Status <0==failure", expectedStatus, actualStatus);

    int expectedLogCount = BANNER_LINES + INIT_FILE_CITATION_LINES + 1;
    assertEquals("Log records written", expectedLogCount, this.junitLoggerHandler.getLog().size());
    for (LogRecord logRecord : this.junitLoggerHandler.getLog()) {
        assertNull("No exceptions in log", logRecord.getThrown());
    }
}

From source file:io.stallion.services.LogFormatter.java

@Override
public String format(LogRecord record) {
    StringBuilder sb = new StringBuilder();
    SimpleDateFormat df = new SimpleDateFormat("MMM dd HH:mm:ss");

    String dateString = df.format(new Date(record.getMillis()));
    String classAndMethod = record.getSourceClassName() + "." + record.getSourceMethodName() + " ";
    classAndMethod = StringUtils.rightPad(classAndMethod, 50);
    sb.append(dateString).append(" ").append(record.getLevel().getLocalizedName()).append(" ")
            .append(classAndMethod).append(formatMessage(record)).append(LINE_SEPARATOR);

    if (record.getThrown() != null) {
        try {//w  w  w  .j  a  va  2 s .c o  m
            StringWriter sw = new StringWriter();
            PrintWriter pw = new PrintWriter(sw);
            record.getThrown().printStackTrace(pw);
            pw.close();
            sb.append(sw.toString());
        } catch (Exception ex) {
            // ignore
        }
    }

    return sb.toString();
}