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:

${:import(org.apache.log4j.Logger)}
private static final Logger LOG = Logger.getLogger(${enclosing_type}.class);

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?

Related posts:

  1. IDEA versus Eclipse
    IDEA has been giving me grief lately. Fed up with mysterious pauses, bugs in svn moves, and crashes even after performing cache-deletion voodoo in IDE, I’m back to trying Eclipse.......
  2. How to increase maven heapspace in hudson builds
    If your maven-built project fails in hudson (especially when you’re using the assembly plugin) and it isn’t a compile or test failure, check the console output. If it says “java.lang.OutOfMemoryError:......
  3. Simple spring integration testing
    Spring has had a really nice unit test framework available for a while now, but the documentation can be a bit daunting. Here’s a super-simple example of adding dependency injection......
  4. Create new junit tests in Eclipse with a keystroke
    The Galileo version of Eclipse doesn’t ship with a default keybinding for creating a unit test for the current class, but you can add one easily enough. Navigate to Preferences......

This entry was posted in Technical HOWTOs and tagged , , . Bookmark the permalink.

One Response to Simple Log4J eclipse template

  1. adaptun says:

    Thanks.
    It has saved me half an hour this day.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">

Additional comments powered by BackType