rspec/rules/S3416/java/rule.adoc
Fred Tingaud 16f6c0aecf
Inline adoc when include has no additional value (#1940)
Inline adoc files when they are included exactly once.

Also fix language tags because this inlining gives us better information
on what language the code is written in.
2023-05-25 14:18:12 +02:00

56 lines
1.5 KiB
Plaintext

== 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
[source,java]
----
public class MyClass {
private final static Logger LOG = LoggerFactory.getLogger(WrongClass.class); // Noncompliant; multiple classes using same logger
}
----
=== Compliant solution
[source,java]
----
public class MyClass {
private final static Logger LOG = LoggerFactory.getLogger(MyClass.class);
}
----
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
=== Message
Update this logger to use the current class.
=== Highlighting
Xxx.class
'''
== Comments And Links
(visible only on this page)
=== on 25 Nov 2015, 09:22:38 Freddy Mallet wrote:
See my comment on relating Google Group thread [~ann.campbell.2]: \https://groups.google.com/forum/?utm_medium=email&utm_source=footer#!msg/sonarqube/7DGhtbqRsHk/j2rDIp6dAwAJ
=== on 7 Jun 2018, 14:17:52 Andrei Epure wrote:
Also requested in \https://groups.google.com/forum/?utm_source=digest&utm_medium=email#!topic/sonarqube/qCK_pZJ7G_Q
endif::env-github,rspecator-view[]