I am writing a web application in Java and using SLF4J for logging.
I’m becoming tired of writing the below line for every class that uses logging:
private static final Logger logger = LoggerFactory.getLogger(ThisClassName.class);
To avoid redundant codes, I am thinking something like
interface Loggable {
Logger logger();
}
and each class can just implement this interface then some magic like AOP inserts the LoggerFactory part.
Has anyone implemented this or knows how to achieve this?
Thanks!
Are you using eclipse? If so, why not just use a code template with a keyword like “logger” and the following template for it:
This way you would just type “logger”, hit shift+space and you are done.