Tuesday, 22 December 2009

Logger template for Eclipse

As always, my blog dies rather quickly with lack of posts. Main reason for that is lack of time to write a nice, long blog entry. I was recently advised by a colleague that a good place to start is to jot down things that are easily forgotten and require googling later on.
So here comes the first one: how to create a template that will save me a bit of typing every time I need to add a logger to a class.

Preferences -> java -> editor -> templates, "new...".

name: log
description: Logger definition
context: java
automatically insert: yes
pattern:
private static final ${typeLogger:newType(org.slf4j.Logger)}
${name:newName(log)} =
${typeFactory:newType(org.slf4j.LoggerFactory)}.getLogger(${enclosing_type}.class);


All that you need to type in your code afterwards is "log" & ctrl+space. Of course it will work just as nicely with any other log library.