Last active
December 16, 2022 18:34
-
-
Save hossain-khan/3f9179f469b673c9dcbd9b41f55c2cb8 to your computer and use it in GitHub Desktop.
Kotlin - Timber Log Live Template - Preview https://user-images.githubusercontent.com/99822/158228177-f0cba204-e354-4d92-b029-41b22ba1f997.png
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
/* | |
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