Class LoggingFeature
- java.lang.Object
-
- org.glassfish.jersey.logging.LoggingFeature
-
- All Implemented Interfaces:
Feature
public class LoggingFeature extends Object implements Feature
This feature enables logging request and/or response on client-side and/or server-side depending on the context'sRuntimeType.The feature may be register programmatically like other features by calling any of
Configurableregister(...)method, i.e.Configurable.register(Class)or by setting any of the configuration property listed bellow.Common configurable properties applies for both client and server and are following:
LOGGING_FEATURE_LOGGER_NAMELOGGING_FEATURE_LOGGER_LEVELLOGGING_FEATURE_VERBOSITYLOGGING_FEATURE_MAX_ENTITY_SIZELOGGING_FEATURE_SEPARATORLOGGING_FEATURE_REDACT_HEADERS
If any of the configuration value is not set, following default values are applied:
- logger name:
org.glassfish.jersey.logging.LoggingFeature - logger level:
Level.FINE - verbosity:
LoggingFeature.Verbosity.PAYLOAD_TEXT - maximum entity size: 8192
- line separator:
DEFAULT_SEPARATOR - redact headers: "Authorization"
Server configurable properties:
Client configurable properties:- Since:
- 2.23
- Author:
- Ondrej Kosatka
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classLoggingFeature.LoggingFeatureBuilderBuilder class for logging feature configuration.static classLoggingFeature.VerbosityVerbositydetermines how detailed message will be logged.
-
Field Summary
Fields Modifier and Type Field Description static StringDEFAULT_LOGGER_LEVELDefault logger level which will be used for logging request and response messages.static StringDEFAULT_LOGGER_NAMEDefault logger name to log request and response messages.static intDEFAULT_MAX_ENTITY_SIZEDefault maximum entity bytes to be logged.static StringDEFAULT_REDACT_HEADERSDefault headers to be redacted.static StringDEFAULT_SEPARATORDefault separator for entity logging.static LoggingFeature.VerbosityDEFAULT_VERBOSITYDefault verbosity for entity logging.static StringLOGGING_FEATURE_LOGGER_LEVELCommon logger level property.static StringLOGGING_FEATURE_LOGGER_LEVEL_CLIENTClient logger level property.static StringLOGGING_FEATURE_LOGGER_LEVEL_SERVERServer logger level property.static StringLOGGING_FEATURE_LOGGER_NAMECommon logger name property.static StringLOGGING_FEATURE_LOGGER_NAME_CLIENTClient logger name property.static StringLOGGING_FEATURE_LOGGER_NAME_SERVERServer logger name property.static StringLOGGING_FEATURE_MAX_ENTITY_SIZECommon property for configuring a maximum number of bytes of entity to be logged.static StringLOGGING_FEATURE_MAX_ENTITY_SIZE_CLIENTClient property for configuring a maximum number of bytes of entity to be logged.static StringLOGGING_FEATURE_MAX_ENTITY_SIZE_SERVERServer property for configuring a maximum number of bytes of entity to be logged.static StringLOGGING_FEATURE_REDACT_HEADERSCommon property for configuring headers to be redacted.static StringLOGGING_FEATURE_REDACT_HEADERS_CLIENTClient property for configuring headers to be redacted.static StringLOGGING_FEATURE_REDACT_HEADERS_SERVERServer property for configuring headers to be redacted.static StringLOGGING_FEATURE_SEPARATORCommon property for configuring logging separator.static StringLOGGING_FEATURE_SEPARATOR_CLIENTClient property for logging separator.static StringLOGGING_FEATURE_SEPARATOR_SERVERServer property for configuring separator.static StringLOGGING_FEATURE_VERBOSITYCommon property for configuring a verbosity of entity.static StringLOGGING_FEATURE_VERBOSITY_CLIENTClient property for configuring a verbosity of entity.static StringLOGGING_FEATURE_VERBOSITY_SERVERServer property for configuring a verbosity of entity.
-
Constructor Summary
Constructors Constructor Description LoggingFeature()Creates the feature with default values.LoggingFeature(Logger logger)Creates the feature with custom logger.LoggingFeature(Logger logger, Integer maxEntitySize)Creates the feature with custom logger and maximum number of bytes of entity to log.LoggingFeature(Logger logger, Level level, LoggingFeature.Verbosity verbosity, Integer maxEntitySize)Creates the feature with custom logger, it's level, message verbosity and maximum number of bytes of entity to log.LoggingFeature(Logger logger, LoggingFeature.Verbosity verbosity)Creates the feature with custom logger and verbosity.LoggingFeature(LoggingFeature.LoggingFeatureBuilder builder)Constructor based on logging feature builder.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static LoggingFeature.LoggingFeatureBuilderbuilder()builder method to create LoggingFeature with required settingsbooleanconfigure(FeatureContext context)A call-back method called when the feature is to be enabled in a given runtime configuration scope.
-
-
-
Field Detail
-
DEFAULT_LOGGER_NAME
public static final String DEFAULT_LOGGER_NAME
Default logger name to log request and response messages.
-
DEFAULT_LOGGER_LEVEL
public static final String DEFAULT_LOGGER_LEVEL
Default logger level which will be used for logging request and response messages.
-
DEFAULT_MAX_ENTITY_SIZE
public static final int DEFAULT_MAX_ENTITY_SIZE
Default maximum entity bytes to be logged.- See Also:
- Constant Field Values
-
DEFAULT_VERBOSITY
public static final LoggingFeature.Verbosity DEFAULT_VERBOSITY
Default verbosity for entity logging. SeeLoggingFeature.Verbosity.
-
DEFAULT_SEPARATOR
public static final String DEFAULT_SEPARATOR
Default separator for entity logging.- See Also:
- Constant Field Values
-
DEFAULT_REDACT_HEADERS
public static final String DEFAULT_REDACT_HEADERS
Default headers to be redacted. If multiple, separate each header with a semicolon.- See Also:
- Constant Field Values
-
LOGGING_FEATURE_LOGGER_NAME
public static final String LOGGING_FEATURE_LOGGER_NAME
Common logger name property.- See Also:
- Constant Field Values
-
LOGGING_FEATURE_LOGGER_LEVEL
public static final String LOGGING_FEATURE_LOGGER_LEVEL
Common logger level property.- See Also:
- Constant Field Values
-
LOGGING_FEATURE_VERBOSITY
public static final String LOGGING_FEATURE_VERBOSITY
Common property for configuring a verbosity of entity.- See Also:
- Constant Field Values
-
LOGGING_FEATURE_MAX_ENTITY_SIZE
public static final String LOGGING_FEATURE_MAX_ENTITY_SIZE
Common property for configuring a maximum number of bytes of entity to be logged.- See Also:
- Constant Field Values
-
LOGGING_FEATURE_SEPARATOR
public static final String LOGGING_FEATURE_SEPARATOR
Common property for configuring logging separator.- See Also:
- Constant Field Values
-
LOGGING_FEATURE_REDACT_HEADERS
public static final String LOGGING_FEATURE_REDACT_HEADERS
Common property for configuring headers to be redacted. The headers are semicolon-separated.- See Also:
- Constant Field Values
-
LOGGING_FEATURE_LOGGER_NAME_SERVER
public static final String LOGGING_FEATURE_LOGGER_NAME_SERVER
Server logger name property.- See Also:
- Constant Field Values
-
LOGGING_FEATURE_LOGGER_LEVEL_SERVER
public static final String LOGGING_FEATURE_LOGGER_LEVEL_SERVER
Server logger level property.- See Also:
- Constant Field Values
-
LOGGING_FEATURE_VERBOSITY_SERVER
public static final String LOGGING_FEATURE_VERBOSITY_SERVER
Server property for configuring a verbosity of entity.- See Also:
- Constant Field Values
-
LOGGING_FEATURE_MAX_ENTITY_SIZE_SERVER
public static final String LOGGING_FEATURE_MAX_ENTITY_SIZE_SERVER
Server property for configuring a maximum number of bytes of entity to be logged.- See Also:
- Constant Field Values
-
LOGGING_FEATURE_SEPARATOR_SERVER
public static final String LOGGING_FEATURE_SEPARATOR_SERVER
Server property for configuring separator.- See Also:
- Constant Field Values
-
LOGGING_FEATURE_REDACT_HEADERS_SERVER
public static final String LOGGING_FEATURE_REDACT_HEADERS_SERVER
Server property for configuring headers to be redacted. The headers are semicolon-separated.- See Also:
- Constant Field Values
-
LOGGING_FEATURE_LOGGER_NAME_CLIENT
public static final String LOGGING_FEATURE_LOGGER_NAME_CLIENT
Client logger name property.- See Also:
- Constant Field Values
-
LOGGING_FEATURE_LOGGER_LEVEL_CLIENT
public static final String LOGGING_FEATURE_LOGGER_LEVEL_CLIENT
Client logger level property.- See Also:
- Constant Field Values
-
LOGGING_FEATURE_VERBOSITY_CLIENT
public static final String LOGGING_FEATURE_VERBOSITY_CLIENT
Client property for configuring a verbosity of entity.- See Also:
- Constant Field Values
-
LOGGING_FEATURE_MAX_ENTITY_SIZE_CLIENT
public static final String LOGGING_FEATURE_MAX_ENTITY_SIZE_CLIENT
Client property for configuring a maximum number of bytes of entity to be logged.- See Also:
- Constant Field Values
-
LOGGING_FEATURE_SEPARATOR_CLIENT
public static final String LOGGING_FEATURE_SEPARATOR_CLIENT
Client property for logging separator.- See Also:
- Constant Field Values
-
LOGGING_FEATURE_REDACT_HEADERS_CLIENT
public static final String LOGGING_FEATURE_REDACT_HEADERS_CLIENT
Client property for configuring headers to be redacted. The headers are semicolon-separated.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
LoggingFeature
public LoggingFeature()
Creates the feature with default values.
-
LoggingFeature
public LoggingFeature(Logger logger)
Creates the feature with custom logger.- Parameters:
logger- the logger to log requests and responses.
-
LoggingFeature
public LoggingFeature(Logger logger, LoggingFeature.Verbosity verbosity)
Creates the feature with custom logger and verbosity.- Parameters:
logger- the logger to log requests and responses.verbosity- verbosity of logged messages. SeeLoggingFeature.Verbosity.
-
LoggingFeature
public LoggingFeature(Logger logger, Integer maxEntitySize)
Creates the feature with custom logger and maximum number of bytes of entity to log.- Parameters:
logger- the logger to log requests and responses.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.
-
LoggingFeature
public LoggingFeature(Logger logger, Level level, LoggingFeature.Verbosity verbosity, Integer maxEntitySize)
Creates the feature with custom logger, it's level, message verbosity and maximum number of bytes of entity to log.- Parameters:
logger- the logger to log requests and responses.level- level on which the messages will be logged.verbosity- verbosity of 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.
-
LoggingFeature
public LoggingFeature(LoggingFeature.LoggingFeatureBuilder builder)
Constructor based on logging feature builder. All parameters are passed through a builder instance.- Parameters:
builder- instance of a builder with required logging feature parameters
-
-
Method Detail
-
configure
public boolean configure(FeatureContext context)
Description copied from interface:FeatureA call-back method called when the feature is to be enabled in a given runtime configuration scope. The responsibility of the feature is to properly update the supplied runtime configuration context and returntrueif the feature was successfully enabled orfalseotherwise.Note that under some circumstances the feature may decide not to enable itself, which is indicated by returning
false. In such case the configuration context does not add the feature to the collection of enabled features and a subsequent call toConfiguration.isEnabled(Feature)orConfiguration.isEnabled(Class)method would returnfalse.
-
builder
public static LoggingFeature.LoggingFeatureBuilder builder()
builder method to create LoggingFeature with required settings- Returns:
- Builder for LoggingFeature
-
-