Skip to content

Instantly share code, notes, and snippets.

@mike-clark-8192
Created July 29, 2025 17:42
Show Gist options
  • Select an option

  • Save mike-clark-8192/b16e4ea7817210a7bf73d016da46c8b1 to your computer and use it in GitHub Desktop.

Select an option

Save mike-clark-8192/b16e4ea7817210a7bf73d016da46c8b1 to your computer and use it in GitHub Desktop.
Android Studio Live Templates for BuildConfig.DEBUG guarded log statements
<templateSet group="AndroidLog">
<template name="dlogd" value="if (BuildConfig.DEBUG) {&#10; android.util.Log.d(TAG, &quot;$METHOD_NAME$: $content$&quot;);&#10;}" description="Log.d(TAG, String)" toReformat="true" toShortenFQNames="true">
<variable name="METHOD_NAME" expression="methodName()" defaultValue="" alwaysStopAt="false" />
<variable name="content" expression="" defaultValue="" alwaysStopAt="true" />
<context>
<option name="JAVA_STATEMENT" value="true" />
</context>
</template>
<template name="dloge" value="if (BuildConfig.DEBUG) {&#10; android.util.Log.e(TAG, &quot;$METHOD_NAME$: $content$&quot;, $exception$);&#10;}" description="Log.e(TAG, String, Exception)" toReformat="true" toShortenFQNames="true">
<variable name="METHOD_NAME" expression="methodName()" defaultValue="" alwaysStopAt="false" />
<variable name="content" expression="" defaultValue="" alwaysStopAt="true" />
<variable name="exception" expression="" defaultValue="e" alwaysStopAt="false" />
<context>
<option name="JAVA_STATEMENT" value="true" />
</context>
</template>
<template name="dlogi" value="if (BuildConfig.DEBUG) {&#10; android.util.Log.i(TAG, &quot;$METHOD_NAME$: $content$&quot;);&#10;}" description="Log.i(TAG, String)" toReformat="true" toShortenFQNames="true">
<variable name="METHOD_NAME" expression="methodName()" defaultValue="" alwaysStopAt="false" />
<variable name="content" expression="" defaultValue="" alwaysStopAt="true" />
<context>
<option name="JAVA_STATEMENT" value="true" />
</context>
</template>
<template name="dlogm" value="if (BuildConfig.DEBUG) {&#10; android.util.Log.d(TAG, $content$);&#10;}" description="Log method name and its arguments" toReformat="true" toShortenFQNames="true">
<variable name="content" expression="groovyScript(&quot;def params = _2.collect {it + ' = [\&quot; + ' + it + ' + \&quot;]'}.join(', '); return '\&quot;' + _1 + '() called' + (params.empty ? '' : ' with: ' + params) + '\&quot;'&quot;, methodName(), methodParameters())" defaultValue="" alwaysStopAt="false" />
<context>
<option name="JAVA_STATEMENT" value="true" />
</context>
</template>
<template name="dlogr" value="if (BuildConfig.DEBUG) {&#10; android.util.Log.d(TAG, &quot;$METHOD_NAME$() returned: &quot; + $result$);&#10;}" description="Log result of this method" toReformat="true" toShortenFQNames="true">
<variable name="METHOD_NAME" expression="methodName()" defaultValue="" alwaysStopAt="false" />
<variable name="result" expression="variableOfType(methodReturnType())" defaultValue="" alwaysStopAt="true" />
<context>
<option name="JAVA_STATEMENT" value="true" />
</context>
</template>
<template name="dlogw" value="if (BuildConfig.DEBUG) {&#10; android.util.Log.w(TAG, &quot;$METHOD_NAME$: $content$&quot;, $exception$);&#10;}" description="Log.w(TAG, String, Exception)" toReformat="true" toShortenFQNames="true">
<variable name="METHOD_NAME" expression="methodName()" defaultValue="" alwaysStopAt="false" />
<variable name="content" expression="" defaultValue="" alwaysStopAt="true" />
<variable name="exception" expression="" defaultValue="e" alwaysStopAt="false" />
<context>
<option name="JAVA_STATEMENT" value="true" />
</context>
</template>
</templateSet>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment