Replace String concatenation with Log4j ParameterizedMessage for readability #905
Labels
enhancement
New feature or request
good first issue
Good for newcomers
help wanted
Extra attention is needed
Is your feature request related to a problem?
Log4j includes parameter substitution which improves readability of log messages and has improved performance and stability over similar
String.format()
:This works well when we are only logging a message. However, we have many cases in our Transport Action exception handling where we use the same message in both the log and exception message (I know because I wrote them!). One such example:
flow-framework/src/main/java/org/opensearch/flowframework/transport/ProvisionWorkflowTransportAction.java
Lines 140 to 144 in 7a93d6c
Log4J's
ParameterizedMessage
class provides a way to construct the message the same way for both cases.What solution would you like?
Example commit inspiring this issue: 86ac8ea
What alternatives have you considered?
StringBuilder
implementation (less readable)String.format()
(performance, can throw exceptions, locale concerns)Do you have any additional context?
There are lots of these. As a good first issue, doing any one of them, or perhaps a class at a time, would be a welcome contribution!
In addition, since most of them follow the same pattern, a new method (per class) of
handleException(Exception e, String formatString, Object... args)
would probably be useful.The text was updated successfully, but these errors were encountered: