Class DatePatternConverter

All Implemented Interfaces:
ArrayPatternConverter, PatternConverter

@Plugin(name="DatePatternConverter", category="Converter") @NullMarked public final class DatePatternConverter extends LogEventPatternConverter implements ArrayPatternConverter
Converts and formats the event's date in a StringBuilder.
  • Field Details

  • Constructor Details

    • DatePatternConverter

      private DatePatternConverter(@Nullable String[] options)
  • Method Details

    • createFormatter

      private static InstantFormatter createFormatter(@Nullable String[] options)
    • createFormatterUnsafely

      private static InstantFormatter createFormatterUnsafely(@Nullable String[] options)
    • readPattern

      private static String readPattern(@Nullable String[] options)
    • decodeNamedPattern

      static String decodeNamedPattern(String pattern)
      Decodes FixedDateFormat named patterns into their corresponding DateTimeFormatter representations.

      In version 2.25.0, FixedDateFormat and FastDateFormat are deprecated in favor of InstantPatternFormatter. We introduced this method to keep backward compatibility with the named patterns provided by FixedDateFormat.

      Parameters:
      pattern - a user provided date invalid input: '&' time formatting pattern
      Returns:
      the transformed formatting pattern where FixedDateFormat named patterns are replaced with their corresponding DateTimeFormatter representations
      Since:
      2.25.0
    • readTimeZone

      private static TimeZone readTimeZone(@Nullable String[] options)
    • readLocale

      private static Locale readLocale(@Nullable String[] options)
    • logOptionReadFailure

      private static void logOptionReadFailure(String[] options, Exception error, String message)
    • newInstance

      public static DatePatternConverter newInstance(String[] options)
      Obtains an instance of pattern converter.
      Parameters:
      options - options, may be null.
      Returns:
      instance of pattern converter.
    • format

      @Deprecated public void format(Date date, StringBuilder buffer)
      Deprecated.
      Starting with version 2.25.0, this method is deprecated and planned to be removed in the next major release.
      Formats the given date to the provided buffer.
      Parameters:
      date - a date
      buffer - a buffer to append to
    • format

      public void format(LogEvent event, StringBuilder output)
      Description copied from class: LogEventPatternConverter
      Formats an event into a string buffer.
      Specified by:
      format in class LogEventPatternConverter
      Parameters:
      event - event to format, may not be null.
      output - string buffer to which the formatted event will be appended. May not be null.
    • format

      @Deprecated public void format(long epochMillis, StringBuilder buffer)
      Deprecated.
      Starting with version 2.25.0, this method is deprecated and planned to be removed in the next major release.
      Formats the given epoch milliseconds to the provided buffer.
      Parameters:
      epochMillis - epoch milliseconds
      buffer - a buffer to append to
    • format

      @Deprecated public void format(Instant instant, StringBuilder buffer)
      Deprecated.
      Starting with version 2.25.0, this method is deprecated and planned to be removed in the next major release.
      Formats the given instant to the provided buffer.
      Parameters:
      instant - an instant
      buffer - a buffer to append to
    • format

      public void format(@Nullable Object object, StringBuilder buffer)
      Description copied from class: LogEventPatternConverter
      Formats an object into a string buffer.
      Specified by:
      format in interface PatternConverter
      Overrides:
      format in class LogEventPatternConverter
      Parameters:
      object - event to format, may not be null.
      buffer - string buffer to which the formatted event will be appended. May not be null.
    • format

      public void format(StringBuilder buffer, @Nullable Object... objects)
      Description copied from interface: ArrayPatternConverter
      Formats an array of Objects.
      Specified by:
      format in interface ArrayPatternConverter
      Parameters:
      buffer - The StringBuilder to add the content to.
      objects - The Object array.
    • getPattern

      public String getPattern()
      Returns:
      the pattern string describing this date format or null if the format does not have a pattern.
    • getTimeZone

      public TimeZone getTimeZone()
      Returns:
      the time zone used by this date format