
* Modify rule S3416: add C# and VB.NET * Add logging frameworks to the list of allowed frameworks * Reverse adding logging frameworks * Fix issues from adoc validation * Review 1 * Fix tabbing * Review 2 * Add list of supported frameworks * Missed renames * Add 'logging' tag * Remove VB.NET * Fix a minor typo --------- Co-authored-by: Gregory Paidis <gregory.paidis@sonarsource.com> Co-authored-by: Gregory Paidis <115458417+gregory-paidis-sonarsource@users.noreply.github.com>
48 lines
1.1 KiB
Plaintext
48 lines
1.1 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
|
|
|
|
'''
|
|
|
|
include::../comments-and-links.adoc[]
|
|
|
|
endif::env-github,rspecator-view[]
|