Ben
Ben

Reputation: 33

Jersey 2.25.1 Client Logging Example

I am using the Jersey 2.25.1 Client and can't get any log output. I've looked at the 2.25.1 documentation - https://www.scribd.com/document/350321996/Jersey-Documentation-2-25-1-User-Guide - and followed what they described for Client logging -

ClientConfig clientConfig = new ClientConfig();
clientConfig.property(LoggingFeature.LOGGING_FEATURE_VERBOSITY_CLIENT, LoggingFeature.Verbosity.PAYLOAD_ANY);
Client client = ClientBuilder.newClient(clientConfig);

Is there an addition step that I am missing? The request is working as expected. The application is running on a Glassfish server and using SLF4J. My understanding was that the output would be logged to the server.log.

Upvotes: 3

Views: 2410

Answers (1)

Geek
Geek

Reputation: 653

You also need to register a logging Filter

clientConfig.register(new MyLogFilter());

You need to create a log filter

class MyLogFilter implements ClientRequestFilter {
    private static final Logger LOG = Logger.getLogger(MyLogFilter.class.getName());

    @Override
    public void filter(ClientRequestContext requestContext) throws IOException {
        LOG.log(Level.INFO, requestContext.getEntity().toString()); // you can configure logging level here
    }
}

Upvotes: 3

Related Questions