When I want to log a message, a variable, or an exception I would like to write it quickly. Therefore I’ve created some templates which generate logging instruction based on slf4j.
Netbeans IDE
I have created the following code template:
1
| |
and I have associated it to the abbreviation log. Than at the cursor:
1 2 3 | |
I type log + TAB and NetBeans expands the text:
1 2 3 4 5 6 7 8 | |
I have also defined the shortcuts:
logd+ TABlogw+ TABlogi+ TABloge+ TAB
defined as:
${LOGGER_CONST default="LOGGER" editable=false}.debug("${logMessage}");${LOGGER_CONST default="LOGGER" editable=false}.warn("${logMessage}");${LOGGER_CONST default="LOGGER" editable=false}.info("${logMessage}");${LOGGER_CONST default="LOGGER" editable=false}.error("${logMessage}", ex);
which generate:
1 2 3 4 | |
Eclipse IDE
Sometime I use Eclipse which has code templates too:
- Windows > Preferences
- Java > Editor > Templates
- New
The log shortcut is defined as:
1 2 | |
while the the various:
logdlogwlogiloge
are defined as:
LOGGER.debug(${word_selection}${});${cursor}LOGGER.warn(${word_selection}${});${cursor}LOGGER.info(${word_selection}${});${cursor}LOGGER.error(${word_selection}${});${cursor}
Post a comment
A comment is submitted by an ordinary e-mail. Your e-mail address will not be published or broadcast.
This blog is moderated, therefore some comments might not be published. Comments are usually approved by the moderator in one/three days.