-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Don't fail on insufficient parameters in ParameterFormatter
(#2337)
#2343
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Personally I would maintain the current logic that throws exceptions, I would just catch them in the call sites.
I looked in Log4j 2.19.0 how formatting was done. Using the StringFormatterMessageFactory
a call to logger.info("Hello %s and %s!", "world")
gives:
2024-03-04 11:18:57,550 main ERROR Unable to format msg: Hello %s and %s!
java.util.MissingFormatArgumentException: Format specifier '%s'
Hello %s and %s!
whereas the default factories for a call to logger.info("Hello {} and {}!", "world")
give just:
Hello world and {}!
I don't think the behavior of Log4j 2.19.0 is correct. I would expect rather:
2024-03-04 11:18:57,550 main ERROR Unable to format msg: Hello {} and {}!
java.lang.IllegalArgumentException: Found 2 argument placeholders, but only 1 was provided.
Hello {} and {}!
log4j-api-test/src/test/java/org/apache/logging/log4j/message/ParameterFormatterTest.java
Show resolved
Hide resolved
log4j-api/src/main/java/org/apache/logging/log4j/message/ParameterFormatter.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
No description provided.