public interface RequestLog
RequestOutcome
.
By default the server provides the DefaultRequestLog
which outputs the NCSA Common log format (with a slight variation explained below).
The user can override the output format by adding an instance of this interface to the server registry.
The format for the request log is "host rfc931 username date:time request statuscode bytes" as defined by the NCSA Common (access logs) format (see link).
However, if the RequestId
is additionally being added to requests, the value of the request Id will be appended to the end of the request log in the form: id=requestId
The resulting format is thus: "host rfc931 username date:time request statuscode bytes id=requestId"Modifier and Type | Method and Description |
---|---|
String |
format(Context context,
RequestOutcome outcome)
Format the provided
RequestOutcome into a String suitable for logging. |
static Handler |
log()
Adds a handler that logs each request.
|
String format(Context context, RequestOutcome outcome)
RequestOutcome
into a String
suitable for logging.context
- the handler contextoutcome
- the resulting outcome of a received request.static Handler log()
RequestLog
in the registry.
By default, the server provides an instance of DefaultRequestLog
which outputs the NCSA Common log format.
import ratpack.handling.RequestLog;
import ratpack.http.client.ReceivedResponse;
import ratpack.test.embed.EmbeddedApp;
import static org.junit.Assert.*;
public class Example {
public static void main(String... args) throws Exception {
EmbeddedApp.fromHandlers(chain -> chain
.all(RequestLog.log())
.all(ctx -> {
ctx.render("ok");
})
).test(httpClient -> {
ReceivedResponse response = httpClient.get();
assertEquals("ok", response.getBody().getText());
// Check log output
});
}
}