Pages

Friday, June 19, 2015

How to set up Eclipse template for inserting SLF4J Logger

Adding private static final Logger logger = LoggerFactory.getLogger(XXX.class); by hand to your Java classes is tiring.

Use Eclipse template. For SLF4J this looks as follows:
private static final Logger LOG 
  = LoggerFactory.getLogger(${enclosing_type}.class);
  ${:import(org.slf4j.Logger,org.slf4j.LoggerFactory)}
Note, that there are two import statements, one for the Logger and another for the LoggerFactory class.

The single steps needed to configure this template in the IDE, is explained in an older post here.