Search in sources :

Example 36 with LogRecord

use of java.util.logging.LogRecord in project j2objc by google.

the class LoggerTest method testInfo_Normal.

/*
	 * Test info(String) with normal values.
	 */
public void testInfo_Normal() {
    this.sharedLogger.setLevel(Level.INFO);
    this.sharedLogger.info("info msg");
    LogRecord r = (LogRecord) CallVerificationStack.getInstance().pop();
    assertTrue(CallVerificationStack.getInstance().empty());
    assertSame(r.getLoggerName(), this.sharedLogger.getName());
    assertEquals(r.getMessage(), "info msg");
    assertSame(r.getResourceBundleName(), this.sharedLogger.getResourceBundleName());
    assertSame(r.getResourceBundle(), this.sharedLogger.getResourceBundle());
    assertSame(r.getSourceClassName(), null);
    assertSame(r.getSourceMethodName(), null);
    assertSame(r.getLevel(), Level.INFO);
    assertNull(r.getParameters());
    assertSame(r.getThrown(), null);
    this.sharedLogger.setLevel(Level.WARNING);
    this.sharedLogger.info("info again");
    assertTrue(CallVerificationStack.getInstance().empty());
}
Also used : LogRecord(java.util.logging.LogRecord)

Example 37 with LogRecord

use of java.util.logging.LogRecord in project j2objc by google.

the class LoggerTest method testLog_LogRecord_InppropriateLevelNoFilterNoParent.

/*
	 * Test log(LogRecord) for a normal log record. Meanwhile the logger has an
	 * inappropriate level, no filter, no parent.
	 */
public void testLog_LogRecord_InppropriateLevelNoFilterNoParent() {
    LogRecord r = new LogRecord(Level.INFO, "testLog_LogRecord_InppropriateLevelNoFilterNoParent");
    this.sharedLogger.setLevel(Level.WARNING);
    this.sharedLogger.log(r);
    assertTrue(CallVerificationStack.getInstance().empty());
    r.setLevel(Level.OFF);
    this.sharedLogger.setLevel(Level.OFF);
    this.sharedLogger.log(r);
    assertTrue(CallVerificationStack.getInstance().empty());
}
Also used : LogRecord(java.util.logging.LogRecord)

Example 38 with LogRecord

use of java.util.logging.LogRecord in project guava by google.

the class CloserTest method testLoggingSuppressor.

public static void testLoggingSuppressor() throws IOException {
    TestLogHandler logHandler = new TestLogHandler();
    Closeables.logger.addHandler(logHandler);
    try {
        Closer closer = new Closer(new Closer.LoggingSuppressor());
        TestCloseable c1 = closer.register(TestCloseable.throwsOnClose(new IOException()));
        TestCloseable c2 = closer.register(TestCloseable.throwsOnClose(new RuntimeException()));
        try {
            throw closer.rethrow(new IOException("thrown"), IOException.class);
        } catch (IOException expected) {
        }
        assertTrue(logHandler.getStoredLogRecords().isEmpty());
        closer.close();
        assertEquals(2, logHandler.getStoredLogRecords().size());
        LogRecord record = logHandler.getStoredLogRecords().get(0);
        assertEquals("Suppressing exception thrown when closing " + c2, record.getMessage());
        record = logHandler.getStoredLogRecords().get(1);
        assertEquals("Suppressing exception thrown when closing " + c1, record.getMessage());
    } finally {
        Closeables.logger.removeHandler(logHandler);
    }
}
Also used : TestLogHandler(com.google.common.testing.TestLogHandler) LogRecord(java.util.logging.LogRecord) IOException(java.io.IOException)

Example 39 with LogRecord

use of java.util.logging.LogRecord in project guice by google.

the class BinderTest method testUserReportedErrorsAreAlsoLogged.

public void testUserReportedErrorsAreAlsoLogged() {
    try {
        Guice.createInjector(new AbstractModule() {

            @Override
            protected void configure() {
                addError(new Message("Whoops!", new IllegalArgumentException()));
            }
        });
        fail();
    } catch (CreationException expected) {
    }
    LogRecord logRecord = Iterables.getOnlyElement(this.logRecords);
    assertContains(logRecord.getMessage(), "An exception was caught and reported. Message: java.lang.IllegalArgumentException");
}
Also used : Message(com.google.inject.spi.Message) LogRecord(java.util.logging.LogRecord)

Example 40 with LogRecord

use of java.util.logging.LogRecord in project liquibase by liquibase.

the class LiquibaseStatusServlet method doGet.

@Override
protected void doGet(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws ServletException, IOException {
    httpServletResponse.setContentType("text/html");
    String logLevelToDisplay = httpServletRequest.getParameter("logLevel");
    Level currentLevel = Level.INFO;
    if (logLevelToDisplay != null) {
        currentLevel = Level.parse(logLevelToDisplay);
    }
    PrintWriter writer = httpServletResponse.getWriter();
    writer.println("<html>");
    writer.println("<head><title>Liquibase Status</title></head>");
    writer.println("<body>");
    if (liquibaseRunLog.size() == 0) {
        writer.println("<b>Liquibase did not run</b>");
    } else {
        writer.println("<b>View level: " + getLevelLink(Level.SEVERE, currentLevel, httpServletRequest) + " " + getLevelLink(Level.WARNING, currentLevel, httpServletRequest) + " " + getLevelLink(Level.INFO, currentLevel, httpServletRequest) + " " + getLevelLink(Level.CONFIG, currentLevel, httpServletRequest) + " " + getLevelLink(Level.FINE, currentLevel, httpServletRequest) + " " + getLevelLink(Level.FINER, currentLevel, httpServletRequest) + " " + getLevelLink(Level.FINEST, currentLevel, httpServletRequest) + "</b>");
        writer.println("<hr>");
        writer.println("<b>Liquibase started at " + DateFormat.getDateTimeInstance().format(new Date(liquibaseRunLog.get(0).getMillis())));
        writer.println("<hr>");
        writer.println("<pre>");
        for (LogRecord record : liquibaseRunLog) {
            if (record.getLevel().intValue() >= currentLevel.intValue()) {
                writer.println(record.getLevel() + ": " + record.getMessage());
                if (record.getThrown() != null) {
                    record.getThrown().printStackTrace(writer);
                }
            }
        }
        writer.println("");
        writer.println("");
        writer.println("</pre>");
        writer.println("<hr>");
        writer.println("<b>Liquibase finished at " + DateFormat.getDateTimeInstance().format(new Date(liquibaseRunLog.get(liquibaseRunLog.size() - 1).getMillis())));
    }
    writer.println("</body>");
    writer.println("</html>");
}
Also used : LogRecord(java.util.logging.LogRecord) Level(java.util.logging.Level) Date(java.util.Date) PrintWriter(java.io.PrintWriter)

Aggregations

LogRecord (java.util.logging.LogRecord)370 Logger (java.util.logging.Logger)62 Test (org.junit.Test)61 Handler (java.util.logging.Handler)24 File (java.io.File)21 IOException (java.io.IOException)21 ByteArrayOutputStream (java.io.ByteArrayOutputStream)16 Level (java.util.logging.Level)16 StreamHandler (java.util.logging.StreamHandler)14 ConsoleHandler (java.util.logging.ConsoleHandler)13 ArrayList (java.util.ArrayList)12 Properties (java.util.Properties)11 Config (com.sun.enterprise.config.serverbeans.Config)10 Formatter (java.util.logging.Formatter)10 SimpleFormatter (java.util.logging.SimpleFormatter)10 LogRecordCollectingLogger (alma.acs.testsupport.LogRecordCollectingLogger)9 BlockingQueueHandler (fish.payara.nucleus.notification.BlockingQueueHandler)9 ActionReport (org.glassfish.api.ActionReport)9 HashMap (java.util.HashMap)7 Subscribe (com.google.common.eventbus.Subscribe)6