Search in sources :

Example 1 with IAccessEvent

use of ch.qos.logback.access.spi.IAccessEvent in project dropwizard by dropwizard.

the class LogbackAccessRequestLogFactory method build.

@Override
public RequestLog build(String name) {
    final Logger logger = (Logger) LoggerFactory.getLogger("http.request");
    logger.setAdditive(false);
    final LoggerContext context = logger.getLoggerContext();
    final LogbackAccessRequestLog requestLog = new LogbackAccessRequestLog();
    final LevelFilterFactory<IAccessEvent> levelFilterFactory = new NullLevelFilterFactory<>();
    final AsyncAppenderFactory<IAccessEvent> asyncAppenderFactory = new AsyncAccessEventAppenderFactory();
    final LayoutFactory<IAccessEvent> layoutFactory = new LogbackAccessRequestLayoutFactory();
    for (AppenderFactory<IAccessEvent> output : appenders) {
        requestLog.addAppender(output.build(context, name, layoutFactory, levelFilterFactory, asyncAppenderFactory));
    }
    return requestLog;
}
Also used : LogbackAccessRequestLayoutFactory(io.dropwizard.request.logging.layout.LogbackAccessRequestLayoutFactory) AsyncAccessEventAppenderFactory(io.dropwizard.request.logging.async.AsyncAccessEventAppenderFactory) IAccessEvent(ch.qos.logback.access.spi.IAccessEvent) NullLevelFilterFactory(io.dropwizard.logging.filter.NullLevelFilterFactory) Logger(ch.qos.logback.classic.Logger) LoggerContext(ch.qos.logback.classic.LoggerContext)

Example 2 with IAccessEvent

use of ch.qos.logback.access.spi.IAccessEvent in project logback-access-spring-boot-starter by akihyro.

the class AbstractLogbackAccessEventsTest method logbackAccessEventWithoutContentLengthResponseHeader.

/**
     * Tests a Logback-access event without a response header of content length.
     */
@Test
public void logbackAccessEventWithoutContentLengthResponseHeader() {
    ResponseEntity<String> response = rest.getForEntity("/test/json", String.class);
    IAccessEvent event = LogbackAccessEventQueuingAppender.appendedEventQueue.pop();
    LogbackAccessEventQueuingListener.appendedEventQueue.pop();
    assertThat(response).hasStatusCode(HttpStatus.OK).doesNotHaveContentLengthHeader().hasBody("{\"TEST-KEY\":\"TEST-VALUE\"}");
    assertThat(event).hasContentLength("{\"TEST-KEY\":\"TEST-VALUE\"}".getBytes(StandardCharsets.UTF_8).length);
}
Also used : IAccessEvent(ch.qos.logback.access.spi.IAccessEvent) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 3 with IAccessEvent

use of ch.qos.logback.access.spi.IAccessEvent in project logback-access-spring-boot-starter by akihyro.

the class AbstractLogbackAccessEventsTest method logbackAccessEventAsynchronously.

/**
     * Tests a Logback-access event asynchronously.
     */
@Test
public void logbackAccessEventAsynchronously() {
    ResponseEntity<String> response = rest.getForEntity("/test/text-asynchronously", String.class);
    IAccessEvent event = LogbackAccessEventQueuingAppender.appendedEventQueue.pop();
    LogbackAccessEventQueuingListener.appendedEventQueue.pop();
    assertThat(response).hasStatusCode(HttpStatus.OK);
    assertThat(event).hasThreadName();
}
Also used : IAccessEvent(ch.qos.logback.access.spi.IAccessEvent) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 4 with IAccessEvent

use of ch.qos.logback.access.spi.IAccessEvent in project logback-access-spring-boot-starter by akihyro.

the class AbstractLogbackAccessEventsTest method logbackAccessEventWithQueryString.

/**
     * Tests a Logback-access event with a query string.
     */
@Test
public void logbackAccessEventWithQueryString() {
    ResponseEntity<String> response = rest.getForEntity("/test/text?query", String.class);
    IAccessEvent event = LogbackAccessEventQueuingAppender.appendedEventQueue.pop();
    LogbackAccessEventQueuingListener.appendedEventQueue.pop();
    assertThat(response).hasStatusCode(HttpStatus.OK);
    assertThat(event).hasRequestUri("/test/text").hasQueryString("?query").hasRequestUrl(HttpMethod.GET, "/test/text?query", "HTTP/1.1");
}
Also used : IAccessEvent(ch.qos.logback.access.spi.IAccessEvent) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 5 with IAccessEvent

use of ch.qos.logback.access.spi.IAccessEvent in project logback-access-spring-boot-starter by akihyro.

the class AbstractLogbackAccessEventsTest method logbackAccessEventToGetEmptyText.

/**
     * Tests a Logback-access event to get empty text.
     */
@Test
public void logbackAccessEventToGetEmptyText() {
    ResponseEntity<String> response = rest.getForEntity("/test/empty-text", String.class);
    IAccessEvent event = LogbackAccessEventQueuingAppender.appendedEventQueue.pop();
    LogbackAccessEventQueuingListener.appendedEventQueue.pop();
    assertThat(response).hasStatusCode(HttpStatus.OK).hasContentLengthHeader(0);
    assertThat(event).hasContentLength(0);
}
Also used : IAccessEvent(ch.qos.logback.access.spi.IAccessEvent) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

IAccessEvent (ch.qos.logback.access.spi.IAccessEvent)18 Test (org.junit.Test)11 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)10 Logger (ch.qos.logback.classic.Logger)1 LoggerContext (ch.qos.logback.classic.LoggerContext)1 NullLevelFilterFactory (io.dropwizard.logging.filter.NullLevelFilterFactory)1 AsyncAccessEventAppenderFactory (io.dropwizard.request.logging.async.AsyncAccessEventAppenderFactory)1 LogbackAccessRequestLayoutFactory (io.dropwizard.request.logging.layout.LogbackAccessRequestLayoutFactory)1 LocalDateTime (java.time.LocalDateTime)1