Signature
def extractLog : Directive1 [ LoggingAdapter ]
Description
Extracts a LoggingAdapter
LoggingAdapter
from the request context which can be used for logging inside the route.
The extractLog
directive is used for providing logging to routes, such that they don’t have to depend on closing over a logger provided in the class body.
See extract and Providing Values to Inner Routes for an overview of similar directives.
Example
Scala
copy source val route =
extractLog { log =>
log . debug ( "I'm logging things in much detail..!" )
complete ( "It's amazing!" )
}
// tests:
Get ( "/abcdef" ) ~> route ~> check {
responseAs [ String ] shouldEqual "It's amazing!"
}
Java
copy source import static akka . http . javadsl . server . Directives . extractLog ;
final Route route = extractLog ( log -> {
log . debug ( "I'm logging things in much detail..!" );
return complete ( "It's amazing!" );
});
// tests:
testRoute ( route ). run ( HttpRequest . GET ( "/abcdef" ))
. assertEntity ( "It's amazing!" );
Found an error in this documentation? The source code for this page can be found
here .
Please feel free to edit and contribute a pull request.