How to get jersey logs at server?
If you want to turn on logging on the server side, you need to register the LoggingFilter Jersey filter (on the container side).
This filter will log request/response headers and entities.
Here's what you need to add to your ResourceConfig
class:
@ApplicationPath("/")
public class MyApplication extends ResourceConfig {
public MyApplication() {
// Resources.
packages(MyResource.class.getPackage().getName());
register(LoggingFilter.class);
}
}
Note that the same filter also works on the client side.
Client client = Client.create();
client.addFilter(new LoggingFilter());
Jersey 2 has deprecated LoggingFilter
and you now need to use LoggingFeature
. In order to use it with a client you can use the following snipette:
this.client = ClientBuilder
.newBuilder()
.property(LoggingFeature.LOGGING_FEATURE_VERBOSITY_CLIENT, LoggingFeature.Verbosity.PAYLOAD_ANY)
.property(LoggingFeature.LOGGING_FEATURE_LOGGER_LEVEL_CLIENT, "WARNING")
.build();
and on the server side:
ResourceConfig config = new ResourceConfig(HelloWorldResource.class);
config.register(LoggingFeature.class);
Jersey 2.0 uses org.glassfish.jersey.filter.LoggingFilter
You can connect it with help of web.xml
<!-- Register my custom provider (not needed if it's in my.package) AND LoggingFilter. -->
<init-param>
<param-name>jersey.config.server.provider.classnames</param-name>
<param-value>org.glassfish.jersey.filter.LoggingFilter</param-value>
</init-param>
More explanations can be found here
upd:
After version 2.23 LoggingFilter
is deprecated and LoggingFeature
should be used.
More info can be found in official documentation