Jersey Logging supports the logging request and response via internal client and server filters, which are
configured and registered by LoggingFeature 's properties.
has been introduced in Jersey 2.23 version and deprecates an older
Jersey of version 3.x fully support all logging features of Jersey 2.x.
LoggingFeature might be discovered by
or initialized by registering on client or server components. Client or server logging filter is initialized
depending on which context is
LoggingFeature registered with.
Defines a logger used to log request and response messages.
Default value is LoggingFeature.DEFAULT_LOGGER_NAME.
Defines level that will be used to log messages by logging filters. Messages will be logged only if the effective level of the logger allows it.
Default value is LoggingFeature.DEFAULT_LOGGER_LEVEL.
Verbosity determines how detailed message will be logged. See LoggingFeature.Verbosity javadoc.
The lowest verbosity LoggingFeature.Verbosity.HEADERS_ONLY will log only request/response headers.
The medium verbosity (LoggingFeature.Verbosity.PAYLOAD_TEXT) will log
request/response headers, as well as an entity if considered a readable text. The
entity is considered a readable text, if MediaType is
or is one of
The highest verbosity LoggingFeature.Verbosity.PAYLOAD_ANY will log all types of an entity (besides the request/response headers.
Note that the entity is logged up to the specified maximum number of bytes (see LoggingFeature.LOGGING_FEATURE_MAX_ENTITY_SIZE).
Default value is LoggingFeature.DEFAULT_VERBOSITY.
Maximum entity size
Maximum number of entity bytes to be logged (and buffered) - if the entity is larger, logging filter will print (and buffer in memory) only the specified number of bytes and print "...more..." string at the end. Negative values are interpreted as zero.
Default value LoggingFeature.DEFAULT_MAX_ENTITY_SIZE.
Redact HTTP headers
HTTP headers with sensitive information can be configured to print "[redacted]" in place of their real values. This should be a string with the names of the HTTP headers to be redacted, each entry separated by a semicolon (;). Header names will be compared in a case-insensitive manner and ignoring initial or trailing whitespaces.
Default value LoggingFeature.DEFAULT_REDACT_HEADERS.
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
suffixed properties, or
An example of initializing server-side logging with the highest verbosity.
Example 22.1. Logging on the client side
ClientConfig clientConfig = new ClientConfig(); clientConfig.property(LoggingFeature.LOGGING_FEATURE_VERBOSITY_CLIENT, LoggingFeature.Verbosity.PAYLOAD_ANY); Client client = ClientBuilder.newClient(clientConfig);
Example 22.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 22.3. Register
ResourceConfig config = new ResourceConfig(HelloWorldResource.class); config.register(LoggingFeature.class);
An example of server-side logging with entity
1 May 09, 2020 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.0 (Apache HttpClient 4.5.9) 9 10 May 09, 2020 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!