Skip to content

Instantly share code, notes, and snippets.

@xcoulon
Last active March 20, 2023 10:18
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save xcoulon/5da14e704aabfbdb00c8 to your computer and use it in GitHub Desktop.
Save xcoulon/5da14e704aabfbdb00c8 to your computer and use it in GitHub Desktop.
SLF4J Logger Template for Eclipse

SLF4J Logger Template for Eclipse

In Preferences>Java>Editor>Templates, create a new template named logger in the Java type members context and with the following pattern:

/** The usual Logger.*/
private static final Logger LOGGER = LoggerFactory.getLogger(${enclosing_type}.class);
${:import('org.slf4j.Logger','org.slf4j.LoggerFactory')}

Also, make sure that Template proposals is selected in Preferences>Java>Editor>Content Assist>Advanced

Now, back in your code, if you type logger and hit Ctrl+Space (or Cmd+Space) and then select the logger proposal, the following code will be inserted in your Java type:

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

...

/** The usual Logger.*/
private static final Logger LOGGER = LoggerFactory.getLogger(MyCurrentType.class);

Note that the import statements will be added only if required.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment