public class DeprecationLogger
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static java.util.regex.Pattern |
WARNING_HEADER_PATTERN
Regular expression to test if a string matches the RFC7234 specification for warning headers.
|
Constructor and Description |
---|
DeprecationLogger(org.apache.logging.log4j.Logger parentLogger)
Creates a new deprecation logger based on the parent logger.
|
Modifier and Type | Method and Description |
---|---|
void |
deprecated(java.lang.String msg,
java.lang.Object... params)
Logs a deprecation message, adding a formatted warning message as a response header on the thread context.
|
void |
deprecatedAndMaybeLog(java.lang.String key,
java.lang.String msg,
java.lang.Object... params)
Adds a formatted warning message as a response header on the thread context, and logs a deprecation message if the associated key has
not recently been seen.
|
static java.lang.String |
escapeAndEncode(java.lang.String s)
Escape and encode a string as a valid RFC 7230 quoted-string.
|
static java.lang.String |
extractWarningValueFromWarningHeader(java.lang.String s)
Extracts the warning value from the value of a warning header that is formatted according to RFC 7234.
|
static java.lang.String |
formatWarning(java.lang.String s)
Format a warning string in the proper warning format by prepending a warn code, warn agent, wrapping the warning string in quotes,
and appending the RFC 7231 date.
|
static void |
removeThreadContext(ThreadContext threadContext)
Remove the
ThreadContext used to add deprecation headers to network responses. |
static void |
setThreadContext(ThreadContext threadContext)
Set the
ThreadContext used to add deprecation headers to network responses. |
public static java.util.regex.Pattern WARNING_HEADER_PATTERN
public DeprecationLogger(org.apache.logging.log4j.Logger parentLogger)
public static void setThreadContext(ThreadContext threadContext)
ThreadContext
used to add deprecation headers to network responses.
This is expected to only be invoked by the Node
's constructor (therefore once outside of tests).
threadContext
- The thread context owned by the ThreadPool
(and implicitly a Node
)java.lang.IllegalStateException
- if this threadContext
has already been setpublic static void removeThreadContext(ThreadContext threadContext)
ThreadContext
used to add deprecation headers to network responses.
This is expected to only be invoked by the Node
's close
method (therefore once outside of tests).
threadContext
- The thread context owned by the ThreadPool
(and implicitly a Node
)java.lang.IllegalStateException
- if this threadContext
is unknown (and presumably already unset before)public void deprecated(java.lang.String msg, java.lang.Object... params)
public void deprecatedAndMaybeLog(java.lang.String key, java.lang.String msg, java.lang.Object... params)
key
- the key used to determine if this deprecation should be loggedmsg
- the message to logparams
- parameters to the messagepublic static java.lang.String extractWarningValueFromWarningHeader(java.lang.String s)
299 Elasticsearch-6.0.0 "warning value" "Sat, 25 Feb 2017 10:27:43 GMT"
, the return value of this method would be warning value
.s
- the value of a warning header formatted according to RFC 7234.public static java.lang.String formatWarning(java.lang.String s)
s
- the warning string to formatpublic static java.lang.String escapeAndEncode(java.lang.String s)
s
- the string to escape and encode