ppkarwasz commented on code in PR #3338:
URL: https://github.com/apache/logging-log4j2/pull/3338#discussion_r1898979648


##########
log4j-core/src/main/java/org/apache/logging/log4j/core/util/internal/instant/InstantPatternDynamicFormatter.java:
##########
@@ -711,23 +488,114 @@ public void formatTo(final StringBuilder buffer, final 
Instant instant) {
                 }
             };
         }
+
+        @Override
+        @Nullable
+        PatternFormatterFactory tryMerge(PatternFormatterFactory other, 
ChronoUnit thresholdPrecision) {
+            // We always merge consecutive static pattern factories
+            if (other instanceof StaticPatternFormatterFactory) {
+                final StaticPatternFormatterFactory otherStatic = 
(StaticPatternFormatterFactory) other;
+                return new StaticPatternFormatterFactory(this.literal + 
otherStatic.literal);
+            }
+            // We also merge a static pattern factory with a DTF factory
+            if (other instanceof DateTimeFormatterPatternFormatterFactory) {
+                final DateTimeFormatterPatternFormatterFactory otherDtf =
+                        (DateTimeFormatterPatternFormatterFactory) other;
+                return new DateTimeFormatterPatternFormatterFactory(
+                        this.pattern + otherDtf.pattern, otherDtf.precision);
+            }
+            return super.tryMerge(other, thresholdPrecision);
+        }
+
+        static String escapeLiteral(String literal) {
+            StringBuilder sb = new StringBuilder(literal.length() + 2);
+            boolean inSingleQuotes = false;
+            for (int i = 0; i < literal.length(); i++) {
+                char c = literal.charAt(i);
+                if (c == '\'') {
+                    if (inSingleQuotes) {
+                        sb.append("'");
+                    }
+                    inSingleQuotes = false;
+                    sb.append("''");
+                } else {
+                    if (!inSingleQuotes) {
+                        sb.append("'");
+                    }
+                    inSingleQuotes = true;
+                    sb.append(c);
+                }
+            }
+            if (inSingleQuotes) {
+                sb.append("'");
+            }
+            return sb.toString();
+        }
     }
 
-    static final class DynamicPatternSequence extends PatternSequence {
+    /**
+     * Formats the pattern using {@link DateTimeFormatter}.
+     */
+    static final class DateTimeFormatterPatternFormatterFactory extends 
PatternFormatterFactory {
 
-        DynamicPatternSequence(final String content) {
-            super(content, contentPrecision(content));
+        /**
+         * @param simplePattern A {@link DateTimeFormatter} pattern containing 
a single letter.

Review Comment:
   Fixed in 
https://github.com/apache/logging-log4j2/pull/3338/commits/148315830d367772c0d89d405be064e92045549f



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscr...@logging.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to