Skip to content
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

Slf4jFormatShouldBeConst: tolerate use of simple LOGGER.info(String) #103

Open
gregallen opened this issue May 28, 2021 · 0 comments
Open

Comments

@gregallen
Copy link

gregallen commented May 28, 2021

This is bad and deserves to be raised as error:

  1. logger.info("blah: " + var);

However, this is sometime tolerable:

  1. logger.info(computeToString(var))

Since the log methods which take no arguments short-cut all the format logic and varargs array creation etc - e.g. see org.slf4j.helpers.MessageFormatter#arrayFormat(java.lang.String, java.lang.Object[], java.lang.Throwable)
Note in particular that with this single argument call slf4j does not parse the passed string for {} placeholders

Hence replacing with this has non-trivial performance impact

logger.info("{}", computeToString(var))

Hence it would be useful if (2) could either be captured by a different check, or permitted

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant