Class ThrowablePatternConverter

    • Field Detail

      • formatters

        @Deprecated
        protected final java.util.List<PatternFormatter> formatters
        Deprecated.
        Kept for binary backward compatibility.
        Returns the list of formatters used to render the suffix.
      • effectiveLineSeparatorProvider

        private final java.util.function.Function<LogEvent,​java.lang.String> effectiveLineSeparatorProvider
    • Method Detail

      • newInstance

        public static ThrowablePatternConverter newInstance​(@Nullable Configuration config,
                                                            @Nullable java.lang.String[] options)
        Creates an instance of the class.
        Parameters:
        config - a configuration
        options - the pattern options
        Returns:
        a new instance
      • format

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

        private static java.util.function.Function<LogEvent,​java.lang.String> createEffectiveLineSeparator​(java.lang.String separator,
                                                                                                                 @Nullable java.lang.String suffix,
                                                                                                                 @Nullable Configuration config,
                                                                                                                 java.util.List<PatternFormatter> suffixFormatters)
        Creates a lambda that returns the effective line separator by concatenating the formatted suffix with the separator.

        At the beginning, there was only separator used as a terminator at the end of every rendered line. Its content was rendered literally without any processing.

        Later on, suffix was added in #61. suffix is functionally identical to separator with the exception that it contains a Pattern Layout conversion pattern. In an ideal world, separator should have been extended to accept patterns. But without giving it a second of thought, just like almost any other Log4j feature, we cheerfully accepted the feature.

        Given two overlapping features, how do we determine the effective line separator?

        
         String effectiveLineSeparator(String separator, String suffix, LogEvent event) {
             String formattedSuffix = format(suffix, event);
             return isNotBlank(formattedSuffix)
                    ? (' ' + formattedSuffix + lineSeparator)
                    : lineSeparator;
         }
         
        Parameters:
        separator - the user-provided separator option
        suffix - the user-provided suffix option containing a Pattern Layout conversion pattern
        config - the configuration to create the Pattern Layout conversion pattern parser
        suffixFormatters - the list of pattern formatters employed to format the suffix
        Returns:
        a lambda that returns the effective line separator by concatenating the formatted suffix with the separator
      • getSuffix

        @Deprecated
        protected java.lang.String getSuffix​(LogEvent logEvent)
        Deprecated.
        Planned to be removed without a replacement
        Returns the formatted suffix pattern.
        Parameters:
        logEvent - the log event to use while formatting the suffix pattern
        Returns:
        the formatted suffix