Search in sources :

Example 11 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)

Example 12 with LogRecord

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

the class MultiPartHeaderModificationTest method testLogMessage.

@Test
public void testLogMessage() {
    final WebTarget target = target().path("multipart/ten");
    MultiPartBean bean = new MultiPartBean("myname", "myvalue");
    MultiPart entity = new MultiPart().bodyPart(bean, new MediaType("x-application", "x-format")).bodyPart("", MediaType.APPLICATION_OCTET_STREAM_TYPE);
    final String UNSENT_HEADER_CHANGES = "Unsent header changes";
    try {
        target.request("text/plain").put(Entity.entity(entity, "multipart/mixed"), String.class);
        assertFalse("BadRequestException can not be thrown just in case JERSEY-2341 is not fixed.", messageLogged);
        LogRecord logRecord = findLogRecord(UNSENT_HEADER_CHANGES);
        assertNull(logRecord);
    } catch (BadRequestException brex) {
        assertTrue("BadRequestException can be thrown just in case JERSEY-2341 is not fixed.", messageLogged);
        LogRecord logRecord = findLogRecord(UNSENT_HEADER_CHANGES);
        assertNotNull("Missing LogRecord for message '" + UNSENT_HEADER_CHANGES + "'.", logRecord);
        assertThat(logRecord.getMessage(), containsString("MIME-Version"));
        assertThat(logRecord.getMessage(), containsString("Content-Type"));
    }
}
Also used : MultiPart(org.glassfish.jersey.media.multipart.MultiPart) LogRecord(java.util.logging.LogRecord) MediaType(javax.ws.rs.core.MediaType) BadRequestException(javax.ws.rs.BadRequestException) WebTarget(javax.ws.rs.client.WebTarget) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Test(org.junit.Test)

Example 13 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 14 with LogRecord

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

the class ExtendedExceptionMapperTest method test.

@Test
public void test() {
    // Format of first param: [exception thrown]-[exception mappers which will return true in isMappable]
    _test("A-A", "A");
    _test("A-AB", "A");
    _test("A-ABC", "A");
    _test("A-ABCD", "A");
    _test("A-ABCDE", "A");
    _test("A-ABCDEX", "A");
    _test("A-C", null);
    _test("A-D", null);
    _test("A-E", null);
    _test("A-D", null);
    _test("A-BCDEX", null);
    _test("A-00000", null);
    _test("A-X", null);
    _test("B-A", "A");
    _test("B-B", "B");
    _test("B-AB", "B");
    _test("B-ABC", "B");
    _test("B-ABCD", "B");
    _test("B-ABCDE", "B");
    _test("B-ABCDEX", "B");
    _test("B-C", null);
    _test("B-D", null);
    _test("B-E", null);
    _test("B-CDEX", null);
    _test("B-X", null);
    _test("B-000", null);
    // C is not an ExtendedExceptionMapper but just ExceptionMapper (always mappable)
    _test("C-C", "C");
    _test("C-A", "C");
    _test("C-AB", "C");
    _test("C-ABC", "C");
    _test("C-AEX", "C");
    _test("C-00000", "C");
    _test("C-ABCDEX", "C");
    _test("C-E", "C");
    _test("C-DE", "C");
    _test("C-D", "C");
    _test("C-X", "C");
    _test("D-000", "C");
    _test("D-A", "C");
    _test("D-B", "C");
    _test("D-C", "C");
    _test("D-D", "D");
    _test("D-E", "C");
    _test("D-ABC", "C");
    _test("D-ABCEX", "C");
    _test("D-ABCDEX", "D");
    _test("D-DE", "D");
    _test("D-ABEX", "C");
    _test("D-AEX", "C");
    _test("D-X", "C");
    _test("E-A", "C");
    _test("E-B", "C");
    _test("E-C", "C");
    _test("E-D", "D");
    _test("E-E", "E");
    _test("E-ABC", "C");
    _test("E-ABCD", "D");
    _test("E-ABCDE", "E");
    _test("E-ABCDEX", "E");
    _test("E-DE", "E");
    _test("E-X", "C");
    _test("E-000000", "C");
    _test("X-A", null);
    _test("X-ABCDE", null);
    _test("X-ABCDEX", "X");
    _test("X-X", "X");
    // Check logs. (??)
    for (final LogRecord logRecord : getLoggedRecords()) {
        for (final String message : new String[] { LocalizationMessages.ERROR_EXCEPTION_MAPPING_ORIGINAL_EXCEPTION(), LocalizationMessages.ERROR_EXCEPTION_MAPPING_THROWN_TO_CONTAINER() }) {
            if (logRecord.getMessage().contains(message) && logRecord.getLevel().intValue() > Level.FINE.intValue()) {
                fail("Log message should be logged at lower (FINE) level: " + message);
            }
        }
    }
}
Also used : LogRecord(java.util.logging.LogRecord) Test(org.junit.Test) JerseyTest(org.glassfish.jersey.test.JerseyTest)

Example 15 with LogRecord

use of java.util.logging.LogRecord in project hudson-2.x by hudson.

the class LogRecorderManager method doRss.

/**
     * Renders the given log recorders as RSS.
     */
/*package*/
static void doRss(StaplerRequest req, StaplerResponse rsp, String recorderName, List<LogRecord> logs) throws IOException, ServletException {
    // filter log records based on the log level
    String level = req.getParameter("level");
    if (level != null) {
        Level threshold = Level.parse(level);
        List<LogRecord> filtered = new ArrayList<LogRecord>();
        for (LogRecord r : logs) {
            if (r.getLevel().intValue() >= threshold.intValue())
                filtered.add(r);
        }
        logs = filtered;
    }
    RSS.forwardToRss("Hudson " + recorderName + " log", "", logs, new FeedAdapter<LogRecord>() {

        public String getEntryTitle(LogRecord entry) {
            return entry.getMessage();
        }

        public String getEntryUrl(LogRecord entry) {
            // TODO: one URL for one log entry?
            return "log";
        }

        public String getEntryID(LogRecord entry) {
            return String.valueOf(entry.getSequenceNumber());
        }

        public String getEntryDescription(LogRecord entry) {
            return Functions.printLogRecord(entry);
        }

        public Calendar getEntryTimestamp(LogRecord entry) {
            GregorianCalendar cal = new GregorianCalendar();
            cal.setTimeInMillis(entry.getMillis());
            return cal;
        }

        public String getEntryAuthor(LogRecord entry) {
            return Mailer.descriptor().getAdminAddress();
        }
    }, req, rsp);
}
Also used : LogRecord(java.util.logging.LogRecord) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) ArrayList(java.util.ArrayList) GregorianCalendar(java.util.GregorianCalendar) Level(java.util.logging.Level)

Aggregations

LogRecord (java.util.logging.LogRecord)289 Test (org.junit.Test)53 Logger (java.util.logging.Logger)45 ByteArrayOutputStream (java.io.ByteArrayOutputStream)16 Handler (java.util.logging.Handler)16 StreamHandler (java.util.logging.StreamHandler)14 ConsoleHandler (java.util.logging.ConsoleHandler)13 File (java.io.File)12 Properties (java.util.Properties)11 SimpleFormatter (java.util.logging.SimpleFormatter)10 LogRecordCollectingLogger (alma.acs.testsupport.LogRecordCollectingLogger)9 Formatter (java.util.logging.Formatter)9 ArrayList (java.util.ArrayList)8 IOException (java.io.IOException)7 Subscribe (com.google.common.eventbus.Subscribe)6 HashMap (java.util.HashMap)6 Level (java.util.logging.Level)6 AtomicReference (java.util.concurrent.atomic.AtomicReference)5 FileHandler (java.util.logging.FileHandler)5 Filter (java.util.logging.Filter)4