Links: Table of Contents | Single HTML

Chapter 21. Logging

21.1. Logging traffic

21.1.1. Introduction

Jersey Logging supports the logging request and response via internal client and server filters, which are configured and registered by LoggingFeature 's properties. LoggingFeature has been introduced in Jersey 2.23 version and deprecates an older LoggingFilter.

LoggingFeature might be discovered by auto-discoverable mechanism or initialized by registering on client or server components. Client or server logging filter is initialized depending on which context is LoggingFeature registered with.

21.1.2. Configuration and registering

21.1.2.1. Configuration options

Configurable options

21.1.2.2. Configuration properties

The feature is enabled on when auto-discoverable mechanism is not disabled and at least one of the feature's property is set. For enabling client or server logging filter one of the common properties or _CLIENT suffixed properties, or _SERVER properties respectively.

An example of initializing server-side logging with the highest verbosity.

Example 21.1. Logging on client-side

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


The LoggingFeature might be registered explicitly on ResourceConfig for server-side logging or on Client for client-side logging.

Example 21.2. Register LoggingFeature via constructor

        ResourceConfig config = new ResourceConfig(HelloWorldResource.class);
        config.register(new LoggingFeature(LOGGER, LoggingFeature.Verbosity.PAYLOAD_ANY));

Following examples demonstrate registering LoggingFeature on server-side with default values and values defined by one of the public constructors (see LoggingFeature).

Example 21.3. Register LoggingFeature class

        ResourceConfig config = new ResourceConfig(HelloWorldResource.class);
        config.register(LoggingFeature.class);

An example of server-side logging with entity Hello World!

  1 May 09, 2016 2:55:33 PM org.glassfish.jersey.logging.LoggingInterceptor log
  2 INFO: 1 * Server has received a request on thread grizzly-http-server-0
  3 1 > GET http://localhost:9998/helloworld
  4 1 > accept: text/plain
  5 1 > accept-encoding: gzip,deflate
  6 1 > connection: Keep-Alive
  7 1 > host: localhost:9998
  8 1 > user-agent: Jersey/3.0-SNAPSHOT (Apache HttpClient 4.5)
  9 
 10 May 09, 2016 2:55:33 PM org.glassfish.jersey.logging.LoggingInterceptor log
 11 INFO: 1 * Server responded with a response on thread grizzly-http-server-0
 12 1 < 200
 13 1 < Content-Type: text/plain
 14 Hello World!