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:

Blogger Jon Scott Stevens said...

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

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

=)

7:23 AM  
Blogger 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.

9:35 AM  

Post a Comment

<< Home