Java logging template in Eclipse

How to create a Java logging template in Eclipse IDE for easy logging using Eclipse.

If you want to do logging in some class, you must first import org.slf4j.Logger and org.slf4j.LoggerFactory, next you must create a logger attribute and after that you can start logging. This is very tedious. You can automate this process by creating an Eclipse logging template.

Go to Window->Preferences, choose Java->Editor->Templates and click New. Fill in this information:

Name: logger
Context: Java type members
Description: create new logger
Pattern:

${:import(org.slf4j.Logger,
org.slf4j.LoggerFactory)}
private static final Logger logger =
LoggerFactory.getLogger(${enclosing_type}.class);


Now if you want to create a logging attribute, just type logging and press CONTROL + SPACE. This will choose this template. Press enter and you have just successfully imported SLF4J Logger, LoggerFactory and created logger attribute.