First suggestion is to have a common base class for all controllers with the following line:
public abstract class AbstractBaseController {
protected Logger logger = Logger.getLogger(this.getClass());
}
Note that the logger is not longer static
- this isn't really an issue with singleton Spring services/controllers, but still I find it a bit awkward. See also: Why do we declare Loggers static final?
Also it is a bit against OO principles and does not allow you to inherit from anything else. This is actually a limitation of a Java language, in Scala/slf4s you can write:
class SomeController extends BaseController with Logging
Where BaseController
is a base class and Logging
is a trait that mixes-in logger
field to a SomeController
class. Very convenient.