Home > eclipse, open source, oss, software development > SLF4J Eclipse templates

SLF4J Eclipse templates

No Gravatar

I’m sure lot of Eclipse developers are happy with Log4E, but for those who does not have Log4E or do not like to “pollute” Eclipse with plugins, I wrote few templates for SLF4J logging.

Just open Preferences and navigate to Java>Editor>Templates

Eclipse Preferences

Eclipse Preferences

…and press Import… button. And import: slf4j-eclipe-templates (download this file first)

Hit OK.

Now in Java editor start to type “logge” (without the quotes) and press CTRL+Space

typing logge...

typing logge...

After hitting enter

logger1

Just as it should be. Imports set, logger created.

I have defined templates for logging to, for example “loginfo” will create a log info message, just like this:

Insert an info level logging

Insert an info level logging

Hit enter, and the output will be:

Log Info insert

Log Info insert

First the LOGGER will be selected, after one TAB you’ll be inside the LOGGER.info() function…

The summary of templates provided:

loggercreate a logger instance with imports
loginfocreate log entry of info level
logerrorcreate log entry of error level
logwarncreate log entry of warn level
logtracecreate log entry of trace level
logdebugcreate log entry of debug level

That’s it.

For Eclipse Editor Templates open Eclipse Help (Infocenter) and navigate to Java development user guide > Concepts > Templates

Share
  1. Thorbjørn
    February 17th, 2010 at 12:00 | #1

    Hi. slf4j provides the {} construct which – properly used – delays the toString evaluation so the isEnabled check can happen inside slf4j. This means that “log.debug(“foo={}”, foo)” is very cheap if debug log is disabled, and the code gets cleaner.

  2. February 18th, 2010 at 01:00 | #2

    @Thorbjørn That’s right. That is described under SLF4J FAQ: Performance.

    I’ll add a new template XML in few days.

    Thx for an advice!

  1. No trackbacks yet.