-
Notifications
You must be signed in to change notification settings - Fork 36
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
Replace String concatenation with Log4j ParameterizedMessage for readability #905
Comments
Hello ! I am new to open-source projects. I am working as junior dev in c#/React, also have 3 year experience with Java. Can I work on this issue? Can you give me some more info? Thanks ! :) |
Hi @boooby19! Welcome! If you have some experience in Java, this should generally be straightforward code-wise, as I've outlined the needed changes in the first comment. Creating your first GitHub PR is a bit more of a challenge. I messed up my first GitHub PR, so I hope you don't follow in my footsteps! :D I linked the steps in another issue but I'll recreate them here. They're also in the CONTRIBUTING document on the main repo page. We use a triangle workflow (you can google that) but basically:
(In this specific case, you're refactoring existing lines so there shouldn't be any new tests needed (item 6) nor javadocs (item 9) so those can be skipped.) If all that works, push ( To respond to PR review comments, just edit your code, commit, and push (to your fork) and the PR will automatically get updated. |
Hello ! I am also new to open-source projects. I would like to try to work on this issue. I am a student at the University and I have some experience with Java, Python, C# and React. Can I work on this issue? |
The DEVELOPER_GUIDE should give you commands you can run to fork/clone, build, and test. |
Yes, I found it |
I have replaced strings "logger.error(errorMessage" in this 40 files: https://github.com/search?q=repo%3Aopensearch-project%2Fflow-framework+%22logger.error%28errorMessage%22&type=code . Can I create PR ? |
Feel free to create a PR at any time and we can discuss the code there. Note that you do not need to replace ones that are not parameterized. The link you showed includes String errorMessage = "There are no templates in the global_context";
logger.error(errorMessage); That's totally fine as there are no substitutions. The main goal is to replace concatenation like this:
with a parameterized string "Failed to retrieve template {} from global context." |
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: