My friend Bruno sent me an interesting tip on how to create a Log4J template at Eclipse. Just follow these steps:
- Go to Window > Preferences > Java > Editor > Templates
- Click New
- Write the string logger at the field Name (this name will be used to call the template)
- At the field Pattern, write the following:
private static final Logger LOGGER = Logger.getLogger(${enclosing_type}.class);
- Click OK
The variable ${enclosing_type} refers to the enclosing type name. When you are ready, write down logger on the field class declaration to have a logger added to the class.