Menu

#512 SLF4J Rules

open
nobody
rules (229)
5
2012-10-07
2008-10-20
No

There are "Jakarta Commons Logging Rules" and "Java Logging Rules", but I would like to see a rule set for proper SLF4J usage.

If you look at the SLF4J FAQ, there is a recommended idiom that is subject to copy/paste errors. I would like an SLF4J rule similar to JCL's "ProperLogger" rule that ensures that the class mentioned in getLogger matches the owner's class:

public class MyClass {
final static Logger logger = LoggerFactory.getLogger(MyClass.class);
... etc
}

works, but:

public class MyOtherClass {
final static Logger logger = LoggerFactory.getLogger(MyClass.class);
... etc
}

fails!

(Note that SLF4J promotes a "Logger" interface, while JCL promotes a "Log" interface.)

Also note that I would love to see a rule that catches code like:

public class MyClass {
final static Logger logger = LoggerFactory.getLogger(MyClass.class.getName());
... etc
}

The additional getName() is redundant because getLogger is overloaded to do just that.

Discussion


Log in to post a comment.