You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@logging.apache.org by "vy (via GitHub)" <gi...@apache.org> on 2024/06/17 08:51:32 UTC

[PR] Fix property substitution for `PatternResolver` (logging-log4j2)

vy opened a new pull request, #2667:
URL: https://github.com/apache/logging-log4j2/pull/2667

   Fixes #2666.


-- 
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-unsubscribe@logging.apache.org

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


Re: [PR] Fix property substitution for `PatternResolver` (logging-log4j2)

Posted by "ppkarwasz (via GitHub)" <gi...@apache.org>.
ppkarwasz commented on code in PR #2667:
URL: https://github.com/apache/logging-log4j2/pull/2667#discussion_r1644103084


##########
log4j-layout-template-json/src/main/java/org/apache/logging/log4j/layout/template/json/resolver/PatternResolver.java:
##########
@@ -71,6 +70,16 @@ public final class PatternResolver implements EventResolver {
                 patternLayout.serialize(logEvent, stringBuilder);
     }
 
+    private static String readPattern(
+            final EventResolverStringSubstitutor substitutor, final TemplateResolverConfig config) {
+        final String pattern = config.getString("pattern");
+        if (Strings.isBlank(pattern)) {
+            throw new IllegalArgumentException("blank pattern: " + config);
+        }
+        final boolean substitutionNeeded = pattern.contains("${");
+        return substitutionNeeded ? substitutor.replace(null, pattern) : pattern;

Review Comment:
   Do we need this logic?
   Seems like premature optimization to me.



-- 
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-unsubscribe@logging.apache.org

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


Re: [PR] Fix property substitution for `PatternResolver` (logging-log4j2)

Posted by "vy (via GitHub)" <gi...@apache.org>.
vy commented on code in PR #2667:
URL: https://github.com/apache/logging-log4j2/pull/2667#discussion_r1644292997


##########
log4j-layout-template-json/src/main/java/org/apache/logging/log4j/layout/template/json/resolver/PatternResolver.java:
##########
@@ -71,6 +70,16 @@ public final class PatternResolver implements EventResolver {
                 patternLayout.serialize(logEvent, stringBuilder);
     }
 
+    private static String readPattern(
+            final EventResolverStringSubstitutor substitutor, final TemplateResolverConfig config) {
+        final String pattern = config.getString("pattern");
+        if (Strings.isBlank(pattern)) {
+            throw new IllegalArgumentException("blank pattern: " + config);
+        }
+        final boolean substitutionNeeded = pattern.contains("${");
+        return substitutionNeeded ? substitutor.replace(null, pattern) : pattern;

Review Comment:
   Removed in 03993a8eebfb88617d0c602781b07d7e3e05e41b.



-- 
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-unsubscribe@logging.apache.org

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


Re: [PR] Fix property substitution for `PatternResolver` (logging-log4j2)

Posted by "vy (via GitHub)" <gi...@apache.org>.
vy commented on PR #2667:
URL: https://github.com/apache/logging-log4j2/pull/2667#issuecomment-2175449983

   @ppkarwasz, as discussed and agreed on,
   
   1. Added `substitute` flag to `@Plugin[Builder]Attribute`
   2. Disabled [configuration file] property substitution for `eventTemplate`, `stackTraceTemplate`, and `EventTemplateAdditionalField#value` attributes
   
   Could you review again, please?


-- 
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-unsubscribe@logging.apache.org

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


Re: [PR] Fix property substitution for `PatternResolver` (logging-log4j2)

Posted by "ppkarwasz (via GitHub)" <gi...@apache.org>.
ppkarwasz commented on PR #2667:
URL: https://github.com/apache/logging-log4j2/pull/2667#issuecomment-2172962463

   Using the features currently provided by `PluginBuilder` a possible alternative approach to introduce lookups in event templates would be:
   
   1. Replace the `@PluginAttribute(value = "eventTemplate")` annotation with `@PluginValue(value = "eventTemplate", substitute = false)` to prevent `PluginBuilder` from expanding the lookups in an inlined event template.
   2. Apply property substitution manually to the event template in a JSON-safe way.
   


-- 
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-unsubscribe@logging.apache.org

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