Skip to content

Instantly share code, notes, and snippets.

@udaybhaskar-v
Last active December 7, 2022 12:56
Show Gist options
  • Save udaybhaskar-v/00095d93692ed1ac9b6f75ceaed53701 to your computer and use it in GitHub Desktop.
Save udaybhaskar-v/00095d93692ed1ac9b6f75ceaed53701 to your computer and use it in GitHub Desktop.
Autogenerate logger statements using live templates.
<templateSet group="Log4j">
<template name="log4j" value="private final org.apache.log4j.Logger log = org.apache.log4j.Logger.getLogger(getClass());" description="log4j declaration" toReformat="true" toShortenFQNames="true">
<context>
<option name="JAVA_DECLARATION" value="true" />
</context>
</template>
<template name="log4d" value="$LOGGER_VAR$.debug(&quot;$EXPR_COPY$ = &quot; + $EXPR$);" description="log4j debug statement" toReformat="true" toShortenFQNames="true">
<variable name="LOGGER_VAR" expression="variableOfType(&quot;org.apache.log4j.Logger&quot;)" defaultValue="" alwaysStopAt="false" />
<variable name="EXPR_COPY" expression="escapeString(EXPR)" defaultValue="" alwaysStopAt="true" />
<variable name="EXPR" expression="variableOfType(&quot;&quot;)" defaultValue="" alwaysStopAt="true" />
<context>
<option name="JAVA_STATEMENT" value="true" />
</context>
</template>
<template name="log4i" value="$LOGGER_VAR$.info(&quot;$EXPR_COPY$ = &quot; + $EXPR$);" description="log4j Info statement" toReformat="true" toShortenFQNames="true">
<variable name="LOGGER_VAR" expression="variableOfType(&quot;org.apache.log4j.Logger&quot;)" defaultValue="" alwaysStopAt="false" />
<variable name="EXPR_COPY" expression="escapeString(EXPR)" defaultValue="" alwaysStopAt="true" />
<variable name="EXPR" expression="variableOfType(&quot;&quot;)" defaultValue="" alwaysStopAt="true" />
<context>
<option name="JAVA_STATEMENT" value="true" />
</context>
</template>
<template name="log4e" value="$LOGGER_VAR$.error(&quot;$EXPR_COPY$ = &quot;, $EXPR$);" description="log4j error statement" toReformat="false" toShortenFQNames="true">
<variable name="LOGGER_VAR" expression="variableOfType(&quot;org.apache.log4j.Logger&quot;)" defaultValue="" alwaysStopAt="false" />
<variable name="EXPR_COPY" expression="escapeString(EXPR)" defaultValue="" alwaysStopAt="false" />
<variable name="EXPR" expression="variableOfType(&quot;java.lang.Exception&quot;)" defaultValue="" alwaysStopAt="true" />
<context>
<option name="COMPLETION" value="true" />
<option name="JAVA_STATEMENT" value="true" />
</context>
</template>
</templateSet>
@udaybhaskar-v
Copy link
Author

udaybhaskar-v commented Oct 30, 2017

create log4j.xml File and paste it in /.IntelliJIdea2017.2/config/templates folder.
Shortcuts for templates
log4j --> Logger variable declaration
log4d --> Logger debug statement
log4i --> Logger info statement
log4e --> Logger error statement

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