Thursday, December 17, 2009

Eclipse template for creating new loggers

Here is the Eclipse template I use for creating new logger fields in my code.
${:import(org.slf4j.Logger, org.slf4j.LoggerFactory)}Logger logger = LoggerFactory.getLogger(${enclosing_type}.class);
${cursor}

The import and the logger declaration are on the same line, i.e. without a separating new line character, whereas ${cursor} is placed on a new line.

To insert the template in Eclipse, go to Window->Preferences->Java->Editor->Templates and select "New...". I usually name the template as "nlog".

Once the template is inserted, you can insert a new logger in Java code, by typing "nlog" (the name of the template) followed by Ctrl-Space.

HTH,

2 comments:

a said...

I dunno Ceki, I like this one better...

http://code.google.com/p/morbok/

=)

Ceki said...

Hey Jon,

Thanks for mentioning morbok and by ricochet lombok. Morbok seems to default to commons-logging instead of SLF4J and lombok, given is agent-based nature, requires a mental jump. Very cool nonetheless.