Search in sources :

Example 81 with LogRecord

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

the class AsyncResponseTest method testResumeException.

private void testResumeException(final String path, final String entity) throws Exception {
    final WebTarget errorResource = target("errorResource");
    final Future<Response> suspended = errorResource.path("suspend").request().async().get();
    final Response response = errorResource.path(path).request().get();
    assertThat(response.getStatus(), equalTo(200));
    assertThat(response.readEntity(String.class), equalTo("ok"));
    final Response suspendedResponse = suspended.get();
    assertThat(suspendedResponse.getStatus(), equalTo(500));
    if (entity != null) {
        assertThat(suspendedResponse.readEntity(String.class), equalTo(entity));
    }
    suspendedResponse.close();
    // Check there is no NPE.
    for (final LogRecord record : getLoggedRecords()) {
        final Throwable thrown = record.getThrown();
        if (thrown != null && thrown instanceof NullPointerException) {
            fail("Unexpected NPE.");
        }
    }
}
Also used : AsyncResponse(javax.ws.rs.container.AsyncResponse) Response(javax.ws.rs.core.Response) LogRecord(java.util.logging.LogRecord) WebTarget(javax.ws.rs.client.WebTarget)

Example 82 with LogRecord

use of java.util.logging.LogRecord in project buck by facebook.

the class ConsoleHandlerTest method consoleHandlerDoesNotWriteBelowLevelToStream.

@Test
public void consoleHandlerDoesNotWriteBelowLevelToStream() {
    ConsoleHandler handler = new ConsoleHandler(ConsoleHandler.utf8OutputStreamWriter(outputStream), new MessageOnlyFormatter(), Level.INFO, state);
    publishAndFlush(handler, new LogRecord(Level.FINE, "Shh.."));
    assertThat(outputStream.size(), equalTo(0));
}
Also used : LogRecord(java.util.logging.LogRecord) Test(org.junit.Test)

Example 83 with LogRecord

use of java.util.logging.LogRecord in project buck by facebook.

the class LogFormatterTest method logRecord.

private static LogRecord logRecord(Level level, String message, String loggerName, int tid, long millis) {
    LogRecord result = new LogRecord(level, message);
    result.setLoggerName(loggerName);
    result.setMillis(millis);
    result.setThreadID(tid);
    return result;
}
Also used : LogRecord(java.util.logging.LogRecord)

Example 84 with LogRecord

use of java.util.logging.LogRecord in project buck by facebook.

the class ConsoleHandlerTest method consoleHandlerCanChangeOutputStreamWithoutClosing.

@Test
public void consoleHandlerCanChangeOutputStreamWithoutClosing() throws IOException {
    FakeOutputStream outputStream1 = new FakeOutputStream();
    FakeOutputStream outputStream2 = new FakeOutputStream();
    ConsoleHandler handler = new ConsoleHandler(ConsoleHandler.utf8OutputStreamWriter(outputStream1), new MessageOnlyFormatter(), Level.INFO, state);
    publishAndFlush(handler, new LogRecord(Level.INFO, "Stream 1"));
    assertThat(outputStream1.toString("UTF-8"), equalTo("Stream 1"));
    threadIdToCommandId.put(49152L, "commandIdForOutputStream2");
    registerOutputStream("commandIdForOutputStream2", outputStream2);
    assertThat(outputStream1.isClosed(), equalTo(false));
    publishAndFlush(handler, newLogRecordWithThreadId(Level.INFO, "Stream 2", 49152));
    assertThat(outputStream1.toString("UTF-8"), equalTo("Stream 1"));
    assertThat(outputStream2.toString("UTF-8"), equalTo("Stream 2"));
    unregisterOutputStream("commandIdForOutputStream2");
    assertThat(outputStream2.isClosed(), equalTo(false));
    publishAndFlush(handler, new LogRecord(Level.INFO, " - DONE"));
    assertThat(outputStream1.toString("UTF-8"), equalTo("Stream 1 - DONE"));
    assertThat(outputStream2.toString("UTF-8"), equalTo("Stream 2"));
}
Also used : LogRecord(java.util.logging.LogRecord) FakeOutputStream(com.facebook.buck.testutil.FakeOutputStream) Test(org.junit.Test)

Example 85 with LogRecord

use of java.util.logging.LogRecord in project buck by facebook.

the class ConsoleHandlerTest method newLogRecordWithThreadId.

private static LogRecord newLogRecordWithThreadId(Level level, String contents, int threadId) {
    LogRecord result = new LogRecord(level, contents);
    result.setThreadID(threadId);
    return result;
}
Also used : LogRecord(java.util.logging.LogRecord)

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