withLog
Description
Allows running an inner route using an alternative LoggingAdapter
in place of the default one.
The logging adapter can be extracted in an inner route using extractLog directly, or used by directives which internally extract the materializer without surfacing this fact in the API.
Example
final LoggingAdapter special = Logging.getLogger(system(), "SpecialRoutes");
final Route sample = path("sample", () ->
extractLog(log -> {
final String msg = "Logging using " + log + "!";
log.debug(msg);
return complete(msg);
}
)
);
final Route route = route(
pathPrefix("special", () ->
withLog(special, () -> sample)
),
sample
);
// tests:
testRoute(route).run(HttpRequest.GET("/sample"))
.assertEntity("Logging using " + system().log() + "!");
testRoute(route).run(HttpRequest.GET("/special/sample"))
.assertEntity("Logging using " + special + "!");
Contents