IDEA live templates for log4j
Live templates are a neat feature in modern IDEA - btw, I'll discuss it in the next episode of my IDE comparison article series. Meanwhile for all IDEA and Log4J users out there, this is a set of live templates I wrote to help me deal with Log4J logger declarations and inserting logging lines in my code:
<?xml version="1.0" encoding="UTF-8"?>
<templateSet group="logging">
<template name="ldeb" value="if ($LOGGER$.isDebugEnabled()) $LOGGER$.debug("$END$");" description="Loggs in debug mode" toReformat="false" toShortenFQNames="true">
<variable name="LOGGER" expression="variableOfType("org.apache.log4j.Logger")" defaultValue="log" alwaysStopAt="true" />
<context>
<option name="JAVA_CODE" value="true" />
<option name="JAVA_COMMENT" value="false" />
<option name="JAVA_STRING" value="false" />
<option name="XML" value="false" />
<option name="HTML" value="false" />
<option name="JSP" value="false" />
<option name="COMPLETION" value="false" />
<option name="OTHER" value="false" />
</context>
</template>
<template name="lerr" value="$LOGGER$.error("$END$");" description="Loggs in error mode" toReformat="false" toShortenFQNames="true">
<variable name="LOGGER" expression="variableOfType("org.apache.log4j.Logger")" defaultValue="log" alwaysStopAt="true" />
<context>
<option name="JAVA_CODE" value="true" />
<option name="JAVA_COMMENT" value="false" />
<option name="JAVA_STRING" value="false" />
<option name="XML" value="false" />
<option name="HTML" value="false" />
<option name="JSP" value="false" />
<option name="COMPLETION" value="false" />
<option name="OTHER" value="false" />
</context>
</template>
<template name="linf" value="if ($LOGGER$.isInfoEnabled()) $LOGGER$.info("$END$");" description="Loggs in info mode" toReformat="false" toShortenFQNames="true">
<variable name="LOGGER" expression="variableOfType("org.apache.log4j.Logger")" defaultValue="log" alwaysStopAt="true" />
<context>
<option name="JAVA_CODE" value="true" />
<option name="JAVA_COMMENT" value="false" />
<option name="JAVA_STRING" value="false" />
<option name="XML" value="false" />
<option name="HTML" value="false" />
<option name="JSP" value="false" />
<option name="COMPLETION" value="false" />
<option name="OTHER" value="false" />
</context>
</template>
<template name="logdec" value="private static final Logger $LOGGER$ = Logger.getLogger($CLASS_NAME$.class);$END$" description="Declares a log4J private static final logger" toReformat="true" toShortenFQNames="true">
<variable name="LOGGER" expression="" defaultValue=""log"" alwaysStopAt="true" />
<variable name="CLASS_NAME" expression="className()" defaultValue="" alwaysStopAt="false" />
<context>
<option name="JAVA_CODE" value="true" />
<option name="JAVA_COMMENT" value="false" />
<option name="JAVA_STRING" value="false" />
<option name="XML" value="false" />
<option name="HTML" value="false" />
<option name="JSP" value="false" />
<option name="COMPLETION" value="false" />
<option name="OTHER" value="false" />
</context>
</template>
<template name="lwarn" value="$LOGGER$.warn("$END$");" description="Loggs in error mode" toReformat="false" toShortenFQNames="true">
<variable name="LOGGER" expression="variableOfType("org.apache.log4j.Logger")" defaultValue="log" alwaysStopAt="true" />
<context>
<option name="JAVA_CODE" value="true" />
<option name="JAVA_COMMENT" value="false" />
<option name="JAVA_STRING" value="false" />
<option name="XML" value="false" />
<option name="HTML" value="false" />
<option name="JSP" value="false" />
<option name="COMPLETION" value="false" />
<option name="OTHER" value="false" />
</context>
</template>
</templateSet>
Just copy this content into a XML file (such as logging.xml), place it in ~/.IntelliJIdea50/config/templates/ and enjoy.