Skip to content

Instantly share code, notes, and snippets.

@hossain-khan
Last active December 16, 2022 18:34
Show Gist options
  • Save hossain-khan/3f9179f469b673c9dcbd9b41f55c2cb8 to your computer and use it in GitHub Desktop.
Save hossain-khan/3f9179f469b673c9dcbd9b41f55c2cb8 to your computer and use it in GitHub Desktop.
/*
See preview screenshot 🏞 https://user-images.githubusercontent.com/99822/158228177-f0cba204-e354-4d92-b029-41b22ba1f997.png
Go to Android Studio Preferences
Editor > Live Templates > Kotlin
Duplicate the existing "soutp" template using the 📄 Duplicate icon on right bar,
and use following template for text.
```
Replace:
println($FORMAT$)
With:
timber.log.Timber.d($FORMAT$)
```
Update description to: Logs function parameter names and values using Timber to Android logcat.
Applicable in kotlin statement (it should be pre-selected for you, since you copied `soutp`)
soutp $FORMAT$ = groovyScript("'\"' + _1.collect { it + ' = [${' + it + '}]'}.join(', ') + '\"'", functionParameters())
*/
groovyScript("def params = _2.collect {it + ' = [${' + it + '}]'}.join(', '); return '\"' + _1 + '() called' + (params.empty ? '' : ' with: ' + params) + '\"'", kotlinFunctionName(), functionParameters())
// Here is one with my personal tag `[HKTAG]` to isolate tag even further.
// Same thing could also be achieved using timber.log.Timber.tag("[HKTAG]").d($FORMAT$)
groovyScript("def params = _2.collect {it + ' = [${' + it + '}]'}.join(', '); return '\"' + '[HKTAG] ' + _1 + '() called' + (params.empty ? '' : ' with: ' + params) + '\"'", kotlinFunctionName(), functionParameters())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment