I'd like to log the called remote host to STDOUT when using Finagle Client. But as far as I see this is not possible via com.twitter.finagle.http.filter.LoggingFilter
; Its #format
(example see below) method cannot access the actual host:
request.remoteHost()
returns0.0.0.0
request.remoteAddress()
returns an object which basically contains the above IPrequest.host()
returns aNone
object
My first guess is/was that accessing the host is not possible because Finagle's client-side load balancing happens deeper in the stack.
This is the test code I use:
LoggingFilter<Request> loggingFilter = new LoggingFilter<>(
new Logger(this.getClass().getSimpleName(), java.util.logging.Logger.getLogger(this.getClass().getSimpleName())),
new LogFormatter<Request, Response>() {
@Override
public String format(Request request, Response reply, Duration replyTime) {
return null;
}
@Override
public String formatException(Request request, Throwable throwable, Duration replyTime) {
return null;
}
});
Service<Request, Response> service = Http.client().newService("localhost:8090,localhost:8091");
Future<Response> response = loggingFilter.andThen(service).apply(Request.apply("/profiles/me"));