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

RSPEC-1312 - Loggers should be "private static final" and should share a naming convention #85

Open
yeikel opened this issue Oct 25, 2022 · 0 comments
Labels
recipe Recipe Requested

Comments

@yeikel
Copy link

yeikel commented Oct 25, 2022

Regardless of the logging framework in use (logback, log4j, commons-logging, java.util.logging, …​), loggers should be:

private: never be accessible outside of its parent class. If another class needs to log something, it should instantiate its own logger.
static: not be dependent on an instance of a class (an object). When logging something, contextual information can of course be provided in the messages but the logger should be created at class level to prevent creating a logger along with each object.
final: be created once and only once per class.

public Logger logger = LoggerFactory.getLogger(Foo.class);  // Noncompliant
private static final Logger LOGGER = LoggerFactory.getLogger(Foo.class);

See : https://rules.sonarsource.com/java/RSPEC-1312

@pway99 pway99 transferred this issue from openrewrite/rewrite Nov 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
recipe Recipe Requested
Projects
Status: Recipes Wanted
Development

No branches or pull requests

1 participant