Package org.glassfish.jersey.logging
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 java.lang.Object implements javax.ws.rs.ext.WriterInterceptor
An interceptor that logs an entity if configured so and provides a common logic forClientLoggingFilter
andServerLoggingFilter
.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) class
LoggingInterceptor.LoggingStream
Helper class used to log an entity to the output stream up to the specified maximum number of bytes.
-
Field Summary
Fields Modifier and Type Field Description (package private) java.util.concurrent.atomic.AtomicLong
_id
private static java.util.Comparator<java.util.Map.Entry<java.lang.String,java.util.List<java.lang.String>>>
COMPARATOR
(package private) static java.lang.String
ENTITY_LOGGER_PROPERTY
The entity stream property(package private) java.util.logging.Level
level
(package private) java.util.logging.Logger
logger
(package private) static java.lang.String
LOGGING_ID_PROPERTY
Logging record id property(package private) int
maxEntitySize
private static java.lang.String
NOTIFICATION_PREFIX
private static java.util.Set<javax.ws.rs.core.MediaType>
READABLE_APP_MEDIA_TYPES
(package private) static java.lang.String
REQUEST_PREFIX
Prefix will be printed before requests(package private) static java.lang.String
RESPONSE_PREFIX
Prefix will be printed before responseprivate static javax.ws.rs.core.MediaType
TEXT_MEDIA_TYPE
(package private) LoggingFeature.Verbosity
verbosity
-
Constructor Summary
Constructors Constructor Description LoggingInterceptor(java.util.logging.Logger logger, java.util.logging.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.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
aroundWriteTo(javax.ws.rs.ext.WriterInterceptorContext writerInterceptorContext)
(package private) java.util.Set<java.util.Map.Entry<java.lang.String,java.util.List<java.lang.String>>>
getSortedHeaders(java.util.Set<java.util.Map.Entry<java.lang.String,java.util.List<java.lang.String>>> headers)
(package private) static boolean
isReadable(javax.ws.rs.core.MediaType mediaType)
Returnstrue
if specifiedMediaType
is considered textual.(package private) void
log(java.lang.StringBuilder b)
Logs aStringBuilder
parameter at required level.(package private) java.io.InputStream
logInboundEntity(java.lang.StringBuilder b, java.io.InputStream stream, java.nio.charset.Charset charset)
private java.lang.StringBuilder
prefixId(java.lang.StringBuilder b, long id)
(package private) static boolean
printEntity(LoggingFeature.Verbosity verbosity, javax.ws.rs.core.MediaType mediaType)
Returnstrue
if entity has to be printed.(package private) void
printPrefixedHeaders(java.lang.StringBuilder b, long id, java.lang.String prefix, javax.ws.rs.core.MultivaluedMap<java.lang.String,java.lang.String> headers)
(package private) void
printRequestLine(java.lang.StringBuilder b, java.lang.String note, long id, java.lang.String method, java.net.URI uri)
(package private) void
printResponseLine(java.lang.StringBuilder b, java.lang.String note, long id, int status)
-
-
-
Field Detail
-
REQUEST_PREFIX
static final java.lang.String REQUEST_PREFIX
Prefix will be printed before requests- See Also:
- Constant Field Values
-
RESPONSE_PREFIX
static final java.lang.String RESPONSE_PREFIX
Prefix will be printed before response- See Also:
- Constant Field Values
-
ENTITY_LOGGER_PROPERTY
static final java.lang.String ENTITY_LOGGER_PROPERTY
The entity stream property
-
LOGGING_ID_PROPERTY
static final java.lang.String LOGGING_ID_PROPERTY
Logging record id property
-
NOTIFICATION_PREFIX
private static final java.lang.String NOTIFICATION_PREFIX
- See Also:
- Constant Field Values
-
TEXT_MEDIA_TYPE
private static final javax.ws.rs.core.MediaType TEXT_MEDIA_TYPE
-
READABLE_APP_MEDIA_TYPES
private static final java.util.Set<javax.ws.rs.core.MediaType> READABLE_APP_MEDIA_TYPES
-
COMPARATOR
private static final java.util.Comparator<java.util.Map.Entry<java.lang.String,java.util.List<java.lang.String>>> COMPARATOR
-
logger
final java.util.logging.Logger logger
-
level
final java.util.logging.Level level
-
_id
final java.util.concurrent.atomic.AtomicLong _id
-
verbosity
final LoggingFeature.Verbosity verbosity
-
maxEntitySize
final int maxEntitySize
-
-
Constructor Detail
-
LoggingInterceptor
LoggingInterceptor(java.util.logging.Logger logger, java.util.logging.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. SeeLoggingFeature.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 Detail
-
log
void log(java.lang.StringBuilder b)
Logs aStringBuilder
parameter at required level.- Parameters:
b
- message to log
-
prefixId
private java.lang.StringBuilder prefixId(java.lang.StringBuilder b, long id)
-
printRequestLine
void printRequestLine(java.lang.StringBuilder b, java.lang.String note, long id, java.lang.String method, java.net.URI uri)
-
printResponseLine
void printResponseLine(java.lang.StringBuilder b, java.lang.String note, long id, int status)
-
printPrefixedHeaders
void printPrefixedHeaders(java.lang.StringBuilder b, long id, java.lang.String prefix, javax.ws.rs.core.MultivaluedMap<java.lang.String,java.lang.String> headers)
-
getSortedHeaders
java.util.Set<java.util.Map.Entry<java.lang.String,java.util.List<java.lang.String>>> getSortedHeaders(java.util.Set<java.util.Map.Entry<java.lang.String,java.util.List<java.lang.String>>> headers)
-
logInboundEntity
java.io.InputStream logInboundEntity(java.lang.StringBuilder b, java.io.InputStream stream, java.nio.charset.Charset charset) throws java.io.IOException
- Throws:
java.io.IOException
-
aroundWriteTo
public void aroundWriteTo(javax.ws.rs.ext.WriterInterceptorContext writerInterceptorContext) throws java.io.IOException, javax.ws.rs.WebApplicationException
- Specified by:
aroundWriteTo
in interfacejavax.ws.rs.ext.WriterInterceptor
- Throws:
java.io.IOException
javax.ws.rs.WebApplicationException
-
isReadable
static boolean isReadable(javax.ws.rs.core.MediaType mediaType)
- Parameters:
mediaType
- the media type of the entity- Returns:
true
if specifiedMediaType
is considered textual.
-
printEntity
static boolean printEntity(LoggingFeature.Verbosity verbosity, javax.ws.rs.core.MediaType mediaType)
Returnstrue
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.
-
-