All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.sonar.l10n.java.rules.java.S3416.html Maven / Gradle / Ivy

There is a newer version: 8.6.0.37351
Show newest version

Why is this an issue?

It is convention to name each class’s logger for the class itself. Doing so allows you to set up clear, communicative logger configuration. Naming loggers by some other convention confuses configuration, and using the same class name for multiple class loggers prevents the granular configuration of each class' logger. Some libraries, such as SLF4J warn about this, but not all do.

This rule raises an issue when a logger is not named for its enclosing class.

Noncompliant code example

public class MyClass {
  private final static Logger LOG = LoggerFactory.getLogger(WrongClass.class);  // Noncompliant; multiple classes using same logger
}

Compliant solution

public class MyClass {
  private final static Logger LOG = LoggerFactory.getLogger(MyClass.class);
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy