Package ratpack.core.handling
Interface RequestLogger
- 
- All Superinterfaces:
- Handler
 
 public interface RequestLogger extends Handler A handler that logs information about the request.Implementations need only implement the log(RequestOutcome)method. This interface provides a default implementation ofhandle()that calls thelog()method before delegating to the next handler. Theof(Action)can also be used to create a request logger.Unless there is a good reason not to, loggers should log to LOGGERat the “info” logging level. How this logging manifests can then be controlled by configuring the logging subsystem in use.import ratpack.core.handling.RequestLogger; import ratpack.test.embed.EmbeddedApp; import static org.junit.jupiter.api.Assertions.*; public class Example { public static void main(String... args) throws Exception { EmbeddedApp.fromHandlers(c -> c .all(RequestLogger.ncsa()) .all(ctx -> ctx.render("ok")) ).test(httpClient -> { assertEquals("ok", httpClient.get().getBody().getText()); }); } }
- 
- 
Field SummaryFields Modifier and Type Field Description static org.slf4j.LoggerLOGGERThe default request logger.static StringLOGGER_NAMEThe name ofLOGGER: "ratpack.request".
 - 
Method SummaryAll Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default voidhandle(Context ctx)Addslog(RequestOutcome)as acontext close action, effectively logging the request.voidlog(RequestOutcome outcome)Format the providedRequestOutcometo the given string builder.static RequestLoggerncsa()Callsncsa(Logger)withLOGGER.static RequestLoggerncsa(org.slf4j.Logger logger)Logs in the NCSA Common Log format.static RequestLoggerof(Action<? super RequestOutcome> action)Creates a request logger with the given action as the implementation of thelog(RequestOutcome)method.
 
- 
- 
- 
Field Detail- 
LOGGER_NAMEstatic final String LOGGER_NAME The name ofLOGGER: "ratpack.request".- See Also:
- Constant Field Values
 
 - 
LOGGERstatic final org.slf4j.Logger LOGGER The default request logger.- See Also:
- LOGGER_NAME
 
 
- 
 - 
Method Detail- 
ofstatic RequestLogger of(Action<? super RequestOutcome> action) Creates a request logger with the given action as the implementation of thelog(RequestOutcome)method.import ratpack.core.handling.RequestLogger; import ratpack.test.embed.EmbeddedApp; import static org.junit.jupiter.api.Assertions.*; public class Example { public static void main(String... args) throws Exception { EmbeddedApp.fromHandlers(c -> c .all(RequestLogger.of(outcome -> RequestLogger.LOGGER.info(outcome.getRequest().getUri()) )) .all(ctx -> ctx.render("ok")) ).test(httpClient -> { assertEquals("ok", httpClient.get().getBody().getText()); }); } }Unless there is reason not to, the action should log at info level to LOGGER.- Parameters:
- action- an action that logs information about the request
- Returns:
- a request logger implementation
 
 - 
ncsastatic RequestLogger ncsa() Callsncsa(Logger)withLOGGER.- Returns:
- a new request logger
 
 - 
ncsastatic RequestLogger ncsa(org.slf4j.Logger logger) Logs in the NCSA Common Log format. 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 theRequestIdis 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"- Parameters:
- logger- the logger to log to, at INFO level
- Returns:
- a new request logger
- See Also:
- NCSA Common Log format documentation.
 
 - 
logvoid log(RequestOutcome outcome) throws Exception Format the providedRequestOutcometo the given string builder.- Parameters:
- outcome- the resulting outcome of a received request
- Throws:
- Exception- any
 
 - 
handledefault void handle(Context ctx) Addslog(RequestOutcome)as acontext close action, effectively logging the request.The handler calls Context.next()after adding the context close action.
 
- 
 
-