Skip to content

Instantly share code, notes, and snippets.

@dumazy
Created September 4, 2017 18:53
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dumazy/fe0ba890ec2b2e4093ba27896a26415d to your computer and use it in GitHub Desktop.
Save dumazy/fe0ba890ec2b2e4093ba27896a26415d to your computer and use it in GitHub Desktop.
Android Studio Live Templates for Log statements in Kotlin
<templateSet group="AndroidLogKotlin">
<template name="logd" value="android.util.Log.d(&quot;$CLASS_NAME$&quot;, &quot;$METHOD_NAME$ (line $LINE$): $MESSAGE$&quot;)$END$" description="Log.d statement" toReformat="false" toShortenFQNames="true">
<variable name="CLASS_NAME" expression="groovyScript(&quot;if(_1.length() &gt; 23) { return _1.substring(0, 23)} else { return _1}&quot;, kotlinClassName())" defaultValue="" alwaysStopAt="true" />
<variable name="METHOD_NAME" expression="kotlinFunctionName()" defaultValue="" alwaysStopAt="false" />
<variable name="LINE" expression="lineNumber()" defaultValue="" alwaysStopAt="false" />
<variable name="MESSAGE" expression="" defaultValue="" alwaysStopAt="true" />
<context>
<option name="KOTLIN_STATEMENT" value="true" />
</context>
</template>
<template name="logi" value="android.util.Log.i(&quot;$CLASS_NAME$&quot;, &quot;$METHOD_NAME$ (line $LINE$): $MESSAGE$&quot;)$END$" description="Log.i statement" toReformat="false" toShortenFQNames="true">
<variable name="CLASS_NAME" expression="groovyScript(&quot;if(_1.length() &gt; 23) { return _1.substring(0, 23)} else { return _1}&quot;, kotlinClassName())" defaultValue="" alwaysStopAt="true" />
<variable name="METHOD_NAME" expression="kotlinFunctionName()" defaultValue="" alwaysStopAt="false" />
<variable name="LINE" expression="lineNumber()" defaultValue="" alwaysStopAt="false" />
<variable name="MESSAGE" expression="" defaultValue="" alwaysStopAt="true" />
<context>
<option name="KOTLIN_STATEMENT" value="true" />
</context>
</template>
<template name="loge" value="android.util.Log.e(&quot;$CLASS_NAME$&quot;, &quot;$METHOD_NAME$ (line $LINE$): $MESSAGE$&quot;, $exception$)$END$" description="Log.e statement" toReformat="false" toShortenFQNames="true">
<variable name="CLASS_NAME" expression="groovyScript(&quot;if(_1.length() &gt; 23) { return _1.substring(0, 23)} else { return _1}&quot;, kotlinClassName())" defaultValue="" alwaysStopAt="true" />
<variable name="METHOD_NAME" expression="kotlinFunctionName()" defaultValue="" alwaysStopAt="false" />
<variable name="LINE" expression="lineNumber()" defaultValue="" alwaysStopAt="false" />
<variable name="MESSAGE" expression="" defaultValue="" alwaysStopAt="true" />
<variable name="exception" expression="" defaultValue="e" alwaysStopAt="false" />
<context>
<option name="KOTLIN_STATEMENT" value="true" />
</context>
</template>
<template name="logw" value="android.util.Log.e(&quot;$CLASS_NAME$&quot;, &quot;$METHOD_NAME$ (line $LINE$): $MESSAGE$&quot;)$END$" description="Log.w statement" toReformat="false" toShortenFQNames="true">
<variable name="CLASS_NAME" expression="groovyScript(&quot;if(_1.length() &gt; 23) { return _1.substring(0, 23)} else { return _1}&quot;, kotlinClassName())" defaultValue="" alwaysStopAt="true" />
<variable name="METHOD_NAME" expression="kotlinFunctionName()" defaultValue="" alwaysStopAt="false" />
<variable name="LINE" expression="lineNumber()" defaultValue="" alwaysStopAt="false" />
<variable name="MESSAGE" expression="" defaultValue="" alwaysStopAt="true" />
<context>
<option name="KOTLIN_STATEMENT" value="true" />
</context>
</template>
</templateSet>
@Baneeishaque
Copy link

It is better for me, if this is ported to java.

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