How to set up Eclipse template for inserting SLF4J Logger

Adding logger definition by hand to your Java classes is tiring:

import org.slf4j.Logger
import org.slf4j.LoggerFactory

private static final Logger logger = LoggerFactory.getLogger(XXX.class);

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 generated, 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

Original post: http://peter-on-java.blogspot.com/2015/06/how-to-set-up-eclipse-template-for.html

Tags ide