Simple Log4J eclipse template

Do you use eclipse and log4j? Do you have a template to add a static Logger instance in classes? Do you have to manually add the import? HA! NO MORE!

Under Preferences > Java > Editor > Templates, click New…

Give the template a name (like “logger”).

Use this for the Pattern:

Click OK, OK, then incant the template by typing the name of the template and invoke Content Assist (ctrl-space on most platforms).

The import line will add org.apache.log4j.Logger to your imports automatically if it doesn’t exist already. Nifty, eh?

Posted in Technical HOWTOs Tagged with: , ,
  • adaptun

    It has saved me half an hour this day.

  • darrin

    Nice… thanks much. Coming from intelliJ I’m still learning some of the tips and tricks related to eclipse. One change I made here was to use ‘.getCanonicalName()’ like this :

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