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

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

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


##########
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 don't believe we need a `try...catch`.



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