Class CallLogger
- Direct Known Subclasses:
BasicCallLogger
,BasicDisabledCallLogger
,BasicTestCallLogger
,BasicTestCaptureCallLogger
,CallLogger.Void
CallLogger
for logging HTTP requests.
Provides the following capabilities:
- Allows incoming HTTP requests to be logged at various
detail levels
. - Allows rules to be defined to handle request logging differently depending on the resulting status code.
- Allows use of stack trace hashing to eliminate duplication of stack traces in log files.
- Allows customization of handling of where requests are logged to.
- Allows configuration via system properties or environment variables.
The following is an example of a logger that logs errors only when debugging is not enabled, and everything when logging is enabled.
Example:
CallLogger
See Also:
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
Builder class.class
Represents no logger -
Field Summary
Modifier and TypeFieldDescriptionstatic final String
System property name for the default enablement setting forCallLogger
objects.static final String
System property name for the logging level setting forCallLogger
objects.static final String
System property name for the default logger name to use forCallLogger
objects.static final String
System property name for the default request detail setting forCallLogger
objects.static final String
System property name for the default response detail setting forCallLogger
objects. -
Constructor Summary
ConstructorDescriptionCallLogger
(BeanStore beanStore) Constructor.CallLogger
(CallLogger.Builder builder) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionstatic CallLogger.Builder
Static creator.protected Logger
Returns the logger to use for logging REST calls.protected CallLoggerRule
getRule
(jakarta.servlet.http.HttpServletRequest req, jakarta.servlet.http.HttpServletResponse res) Given the specified servlet request/response, find the rule that applies to it.protected CallLogger.Builder
Initializer.protected boolean
isDebug
(jakarta.servlet.http.HttpServletRequest req) Returnstrue if debug is enabled on this request.protected boolean
isEnabled
(CallLoggerRule rule, jakarta.servlet.http.HttpServletRequest req) Returnstrue if logging is enabled for this request.void
log
(jakarta.servlet.http.HttpServletRequest req, jakarta.servlet.http.HttpServletResponse res) Called at the end of a servlet request to log the request.protected void
Logs the specified message to the logger.toString()
-
Field Details
-
SP_logger
System property name for the default logger name to use forCallLogger
objects.Can also use a
JUNEAU_RESTLOGGER_LOGGER environment variable.If not specified, the default is
"global" .- See Also:
-
SP_enabled
System property name for the default enablement setting forCallLogger
objects.Can also use a
JUNEAU_RESTLOGGER_ENABLED environment variable.The possible values are:
"ALWAYS"
(default) - Logging is enabled."NEVER"
- Logging is disabled."CONDITIONALLY"
- Logging is enabled if it passes theCallLogger.Builder.enabledTest(Predicate)
test.
- See Also:
-
SP_requestDetail
System property name for the default request detail setting forCallLogger
objects.Can also use a
JUNEAU_RESTLOGGER_REQUESTDETAIL environment variable."STATUS_LINE"
(default) - Log only the status line."HEADER"
- Log the status line and headers."ENTITY"
- Log the status line and headers and content if available.
- See Also:
-
SP_responseDetail
System property name for the default response detail setting forCallLogger
objects.Can also use a
JUNEAU_RESTLOGGER_RESPONSEDETAIL environment variable."STATUS_LINE"
(default) - Log only the status line."HEADER"
- Log the status line and headers."ENTITY"
- Log the status line and headers and content if available.
- See Also:
-
SP_level
System property name for the logging level setting forCallLogger
objects.Can also use a
JUNEAU_RESTLOGGER_LEVEL environment variable.- See Also:
-
-
Constructor Details
-
CallLogger
Constructor.Subclasses typically override the
init(BeanStore)
method when using this constructor.- Parameters:
beanStore
- The bean store containing injectable beans for this logger.
-
CallLogger
Constructor.- Parameters:
builder
- The builder for this logger.
-
-
Method Details
-
create
Static creator.- Parameters:
beanStore
- The bean store to use for creating beans.- Returns:
- A new builder for this object.
-
init
Initializer.Subclasses should override this method to make modifications to the builder used to create this logger.
- Parameters:
beanStore
- The bean store containing injectable beans for this logger.- Returns:
- A new builder object.
-
log
public void log(jakarta.servlet.http.HttpServletRequest req, jakarta.servlet.http.HttpServletResponse res) Called at the end of a servlet request to log the request.- Parameters:
req
- The servlet request.res
- The servlet response.
-
getRule
protected CallLoggerRule getRule(jakarta.servlet.http.HttpServletRequest req, jakarta.servlet.http.HttpServletResponse res) Given the specified servlet request/response, find the rule that applies to it.This method can be overridden to provide specialized logic for finding rules.
- Parameters:
req
- The servlet request.res
- The servlet response.- Returns:
- The applicable logging rule, or the default rule if not found. Never
null .
-
isDebug
Returnstrue if debug is enabled on this request.Looks for the request attribute
"Debug" to determine whether debug is enabled.This method can be overridden to provide specialized logic for determining whether debug mode is enabled on a request.
- Parameters:
req
- The HTTP request being logged.- Returns:
true if debug is enabled on this request.- See Also:
-
isEnabled
Returnstrue if logging is enabled for this request.Uses the enabled and enabled-test settings on the matched rule and this logger to determine whether a REST call should be logged.
This method can be overridden to provide specialized logic for determining whether a REST call should be logged.
- Parameters:
rule
- The first matching rule. Nevernull .req
- The HTTP request.- Returns:
true if logging is enabled for this request.
-
getLogger
Returns the logger to use for logging REST calls.Returns the logger specified in the builder, or
Logger.getGlobal()
if it wasn't specified.This method can be overridden in subclasses to provide a different logger.
- Returns:
- The logger to use for logging REST calls.
-
log
Logs the specified message to the logger.Subclasses can override this method to capture messages being sent to the logger and handle it differently.
- Parameters:
level
- The log level.msg
- The log message.e
- The exception.
-
toString
-