You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@logging.apache.org by "adwsingh (via GitHub)" <gi...@apache.org> on 2023/02/16 11:37:21 UTC

[GitHub] [logging-log4j2] adwsingh commented on a diff in pull request #1278: Don't use regex to detect MessagePattern

adwsingh commented on code in PR #1278:
URL: https://github.com/apache/logging-log4j2/pull/1278#discussion_r1108356964


##########
log4j-api/src/main/java/org/apache/logging/log4j/message/FormattedMessage.java:
##########
@@ -184,20 +182,20 @@ protected Message getMessage(final String msgPattern, final Object[] args, final
         try {
             final MessageFormat format = new MessageFormat(msgPattern);
             final Format[] formats = format.getFormats();
-            if (formats != null && formats.length > 0) {
+            if (formats.length > 0) {
                 return new MessageFormatMessage(locale, msgPattern, args);
             }
         } catch (final Exception ignored) {
             // Obviously, the message is not a proper pattern for MessageFormat.
         }
         try {
-            if (MSG_PATTERN.matcher(msgPattern).find()) {
-                return new StringFormattedMessage(locale, msgPattern, args);
+            if (ParameterizedMessage.countArgumentPlaceholders(msgPattern) > 0) {
+                return new ParameterizedMessage(msgPattern, args, aThrowable);
             }
         } catch (final Exception ignored) {
-            // Also not properly formatted.
+            // Not a valid parameterized message.
         }

Review Comment:
   I felt so but erred on the side of caution. Removed now.



-- 
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