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 Type
    Method
    Description
    void
    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

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • newInstance

      public static RequestDurationPatternConverter newInstance(String[] options)
      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

      public void format(org.apache.logging.log4j.core.LogEvent event, StringBuilder toAppendTo)
      Specified by:
      format in class org.apache.logging.log4j.core.pattern.LogEventPatternConverter
    • getRequestDuration

      public 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. 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)