Created
July 29, 2025 17:42
-
-
Save mike-clark-8192/b16e4ea7817210a7bf73d016da46c8b1 to your computer and use it in GitHub Desktop.
Android Studio Live Templates for BuildConfig.DEBUG guarded log statements
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <templateSet group="AndroidLog"> | |
| <template name="dlogd" value="if (BuildConfig.DEBUG) { android.util.Log.d(TAG, "$METHOD_NAME$: $content$"); }" 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) { android.util.Log.e(TAG, "$METHOD_NAME$: $content$", $exception$); }" 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) { android.util.Log.i(TAG, "$METHOD_NAME$: $content$"); }" 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) { android.util.Log.d(TAG, $content$); }" description="Log method name and its arguments" toReformat="true" toShortenFQNames="true"> | |
| <variable name="content" expression="groovyScript("def params = _2.collect {it + ' = [\" + ' + it + ' + \"]'}.join(', '); return '\"' + _1 + '() called' + (params.empty ? '' : ' with: ' + params) + '\"'", methodName(), methodParameters())" defaultValue="" alwaysStopAt="false" /> | |
| <context> | |
| <option name="JAVA_STATEMENT" value="true" /> | |
| </context> | |
| </template> | |
| <template name="dlogr" value="if (BuildConfig.DEBUG) { android.util.Log.d(TAG, "$METHOD_NAME$() returned: " + $result$); }" 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) { android.util.Log.w(TAG, "$METHOD_NAME$: $content$", $exception$); }" 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