Skip to content

Instantly share code, notes, and snippets.

@timtsj
Created March 19, 2020 06:05
Show Gist options
  • Save timtsj/f82373190e1fb3a53f337d5c868ca533 to your computer and use it in GitHub Desktop.
Save timtsj/f82373190e1fb3a53f337d5c868ca533 to your computer and use it in GitHub Desktop.
AndroidLogKotlin template
<templateSet group="AndroidLogKotlin">
<template name="logm" value="android.util.Log.d(&quot;$NAME$&quot;, $FORMAT$)" description="Log method name and its arguments" toReformat="true" toShortenFQNames="true">
<variable name="NAME" expression="groovyScript(&quot;_1.take(Math.min(23, _1.length()));&quot;, kotlinClassName())" defaultValue="" alwaysStopAt="false" />
<variable name="FORMAT" expression="groovyScript(&quot;def params = _2.collect {it + ' = [$' + it + ']'}.join(', '); return '\&quot;' + _1 + '() called' + (params.empty ? '' : ' with: ' + params) + '\&quot;'&quot;, kotlinFunctionName(), functionParameters())" defaultValue="" alwaysStopAt="false" />
<context>
<option name="KOTLIN_STATEMENT" value="true" />
</context>
</template>
<template name="logd" value="android.util.Log.d(&quot;$NAME$&quot;, &quot;$METHOD_NAME$: $content$&quot;)" description="Log.d(String)" toReformat="true" toShortenFQNames="true">
<variable name="NAME" expression="groovyScript(&quot;_1.take(Math.min(23, _1.length()));&quot;, kotlinClassName())" defaultValue="" alwaysStopAt="false" />
<variable name="METHOD_NAME" expression="kotlinFunctionName()" defaultValue="" alwaysStopAt="false" />
<variable name="content" expression="" defaultValue="" alwaysStopAt="true" />
<context>
<option name="KOTLIN_STATEMENT" value="true" />
</context>
</template>
<template name="loge" value="android.util.Log.e(&quot;$NAME$&quot;, &quot;$METHOD_NAME$: $content$&quot;, $exception$)" description="Log.e(Exception, String)" toReformat="true" toShortenFQNames="true">
<variable name="NAME" expression="groovyScript(&quot;_1.take(Math.min(23, _1.length()));&quot;, kotlinClassName())" defaultValue="" alwaysStopAt="false" />
<variable name="METHOD_NAME" expression="kotlinFunctionName()" defaultValue="" alwaysStopAt="false" />
<variable name="content" expression="" defaultValue="" alwaysStopAt="true" />
<variable name="exception" expression="" defaultValue="e" alwaysStopAt="true" />
<context>
<option name="KOTLIN_STATEMENT" value="true" />
</context>
</template>
<template name="logi" value="android.util.Log.i(&quot;$NAME$&quot;, &quot;$METHOD_NAME$: $content$&quot;)" description="Log.i(String)" toReformat="true" toShortenFQNames="true">
<variable name="NAME" expression="groovyScript(&quot;_1.take(Math.min(23, _1.length()));&quot;, kotlinClassName())" defaultValue="" alwaysStopAt="false" />
<variable name="METHOD_NAME" expression="kotlinFunctionName()" defaultValue="" alwaysStopAt="false" />
<variable name="content" expression="" defaultValue="" alwaysStopAt="true" />
<context>
<option name="KOTLIN_STATEMENT" value="true" />
</context>
</template>
<template name="logw" value="android.util.Log.w(&quot;$NAME$&quot;, &quot;$METHOD_NAME$: $content$&quot;)" description="Log.w(Exception, String)" toReformat="true" toShortenFQNames="true">
<variable name="NAME" expression="groovyScript(&quot;_1.take(Math.min(23, _1.length()));&quot;, kotlinClassName())" defaultValue="" alwaysStopAt="false" />
<variable name="METHOD_NAME" expression="kotlinFunctionName()" defaultValue="" alwaysStopAt="false" />
<variable name="content" expression="" defaultValue="" alwaysStopAt="true" />
<context>
<option name="KOTLIN_STATEMENT" value="true" />
</context>
</template>
<template name="logwtf" value="android.util.Log.wtf(&quot;$NAME$&quot;, &quot;$METHOD_NAME$: $content$&quot;)" description="Log.wtf(Exception, String)" toReformat="true" toShortenFQNames="true">
<variable name="NAME" expression="groovyScript(&quot;_1.take(Math.min(23, _1.length()));&quot;, kotlinClassName())" defaultValue="" alwaysStopAt="false" />
<variable name="METHOD_NAME" expression="kotlinFunctionName()" defaultValue="" alwaysStopAt="false" />
<variable name="content" expression="" defaultValue="" alwaysStopAt="true" />
<context>
<option name="KOTLIN_STATEMENT" value="true" />
</context>
</template>
<template name="logt" value="private const val TAG = &quot;$NAME$&quot;" description="A static logtag with your current classname" toReformat="true" toShortenFQNames="true">
<variable name="NAME" expression="groovyScript(&quot;_1.take(Math.min(23, _1.length()));&quot;, kotlinClassName())" defaultValue="" alwaysStopAt="false" />
<context>
<option name="KOTLIN" value="true" />
</context>
</template>
</templateSet>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment