Class LoggingInterceptor

java.lang.Object
org.glassfish.jersey.logging.LoggingInterceptor
All Implemented Interfaces:
javax.ws.rs.ext.WriterInterceptor
Direct Known Subclasses:
ClientLoggingFilter, ServerLoggingFilter

abstract class LoggingInterceptor extends Object implements javax.ws.rs.ext.WriterInterceptor
An interceptor that logs an entity if configured so and provides a common logic for ClientLoggingFilter and ServerLoggingFilter.
  • Field Details

    • REQUEST_PREFIX

      static final String REQUEST_PREFIX
      Prefix will be printed before requests
      See Also:
    • RESPONSE_PREFIX

      static final String RESPONSE_PREFIX
      Prefix will be printed before response
      See Also:
    • ENTITY_LOGGER_PROPERTY

      static final String ENTITY_LOGGER_PROPERTY
      The entity stream property
    • LOGGING_ID_PROPERTY

      static final String LOGGING_ID_PROPERTY
      Logging record id property
    • NOTIFICATION_PREFIX

      private static final String NOTIFICATION_PREFIX
      See Also:
    • TEXT_MEDIA_TYPE

      private static final javax.ws.rs.core.MediaType TEXT_MEDIA_TYPE
    • READABLE_APP_MEDIA_TYPES

      private static final Set<javax.ws.rs.core.MediaType> READABLE_APP_MEDIA_TYPES
    • COMPARATOR

      private static final Comparator<Map.Entry<String,List<String>>> COMPARATOR
    • logger

      final Logger logger
    • level

      final Level level
    • _id

      final AtomicLong _id
    • verbosity

      final LoggingFeature.Verbosity verbosity
    • maxEntitySize

      final int maxEntitySize
  • Constructor Details

    • LoggingInterceptor

      LoggingInterceptor(Logger logger, Level level, LoggingFeature.Verbosity verbosity, int maxEntitySize)
      Creates a logging filter with custom logger and entity logging turned on, but potentially limiting the size of entity to be buffered and logged.
      Parameters:
      logger - the logger to log messages to.
      level - level at which the messages will be logged.
      verbosity - verbosity of the logged messages. See LoggingFeature.Verbosity.
      maxEntitySize - 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.
  • Method Details

    • log

      void log(StringBuilder b)
      Logs a StringBuilder parameter at required level.
      Parameters:
      b - message to log
    • prefixId

      private StringBuilder prefixId(StringBuilder b, long id)
    • printRequestLine

      void printRequestLine(StringBuilder b, String note, long id, String method, URI uri)
    • printResponseLine

      void printResponseLine(StringBuilder b, String note, long id, int status)
    • printPrefixedHeaders

      void printPrefixedHeaders(StringBuilder b, long id, String prefix, javax.ws.rs.core.MultivaluedMap<String,String> headers)
    • getSortedHeaders

      Set<Map.Entry<String,List<String>>> getSortedHeaders(Set<Map.Entry<String,List<String>>> headers)
    • logInboundEntity

      InputStream logInboundEntity(StringBuilder b, InputStream stream, Charset charset) throws IOException
      Throws:
      IOException
    • aroundWriteTo

      public void aroundWriteTo(javax.ws.rs.ext.WriterInterceptorContext writerInterceptorContext) throws IOException, javax.ws.rs.WebApplicationException
      Specified by:
      aroundWriteTo in interface javax.ws.rs.ext.WriterInterceptor
      Throws:
      IOException
      javax.ws.rs.WebApplicationException
    • isReadable

      static boolean isReadable(javax.ws.rs.core.MediaType mediaType)
      Returns true if specified MediaType is considered textual.

      See READABLE_APP_MEDIA_TYPES.

      Parameters:
      mediaType - the media type of the entity
      Returns:
      true if specified MediaType is considered textual.
    • printEntity

      static boolean printEntity(LoggingFeature.Verbosity verbosity, javax.ws.rs.core.MediaType mediaType)
      Returns true if entity has to be printed.
      Parameters:
      verbosity - the configured verbosity .
      mediaType - the media type of the payload.
      Returns:
      true if entity has to be printed.