My friend Bruno sent me an interesting tip on how to create a Log4J template at Eclipse. Just follow these steps:

  1. Go to Window > Preferences > Java > Editor > Templates
  2. Click New
  3. Write the string logger at the field Name (this name will be used to call the template)
  4. At the field Pattern, write the following:

    private static final Logger LOGGER = Logger.getLogger(${enclosing_type}.class);

  5. 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.

Tags: , , , ,