Class RequestDurationPatternConverter
java.lang.Object
org.apache.logging.log4j.core.pattern.AbstractPatternConverter
org.apache.logging.log4j.core.pattern.LogEventPatternConverter
org.veupathdb.lib.container.jaxrs.utils.logging.RequestDurationPatternConverter
- All Implemented Interfaces:
org.apache.logging.log4j.core.pattern.PatternConverter
@Plugin(name="RequestDurationPatternConverter",
category="Converter")
public final class RequestDurationPatternConverter
extends org.apache.logging.log4j.core.pattern.LogEventPatternConverter
This class is identical to Log4J 2.x's MdcPatternConverter EXCEPT for a
change to the format() method where we convert the request start time into
a request duration at the time this line is being logged. Unfortunately,
it is a lot less efficient than the hack we used in Log4j 1.x since we need
to parse the stored String value back into a Long for comparison to the
current time. But the feature is handy enough to warrant this cost.
-
Field Summary
Fields inherited from class org.apache.logging.log4j.core.pattern.AbstractPatternConverter
LOGGER
Fields inherited from interface org.apache.logging.log4j.core.pattern.PatternConverter
CATEGORY
-
Method Summary
Modifier and TypeMethodDescriptionvoid
format
(org.apache.logging.log4j.core.LogEvent event, StringBuilder toAppendTo) static String
getRequestDuration
(Object requestStartTime) Converts the object passed to a String first, then tries to convert to a Long for comparison against the current system time (millisecs) in order to calculate the duration from a start time to now.newInstance
(String[] options) Obtains an instance of PropertiesPatternConverter.Methods inherited from class org.apache.logging.log4j.core.pattern.LogEventPatternConverter
emptyVariableOutput, format, handlesThrowable, isVariable
Methods inherited from class org.apache.logging.log4j.core.pattern.AbstractPatternConverter
getName, getStyleClass
-
Method Details
-
newInstance
Obtains an instance of PropertiesPatternConverter.- Parameters:
options
- options, may be null or first element contains name of property to format.- Returns:
- instance of PropertiesPatternConverter.
-
format
- Specified by:
format
in classorg.apache.logging.log4j.core.pattern.LogEventPatternConverter
-
getRequestDuration
Converts the object passed to a String first, then tries to convert to a Long for comparison against the current system time (millisecs) in order to calculate the duration from a start time to now. After subtraction, converts back to a String and appends "ms" before returning.- Parameters:
requestStartTime
- (String) object stored in MDC as a start time (should be convertable to Long)- Returns:
- the duration between the start time and "now" in milliseconds (with "ms" suffix)
-