Last active
October 20, 2020 09:42
-
-
Save rayworks/89a6fb719c0a9aa53c25f09691b97b4f to your computer and use it in GitHub Desktop.
Prints Caller function names
This file contains 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
fun printCallerContextInfo(cb: () -> String, levelDepth : Int = 7) { | |
if (!BuildConfig.DEBUG) | |
return | |
val stackTrace = Thread.currentThread().stackTrace | |
var i = 0 | |
val builder = StringBuilder() | |
builder.append("${cb.invoke()} : ") | |
for (ste in stackTrace) { | |
i++ | |
if (i > levelDepth) { | |
break | |
} | |
val className = ste.className | |
val methodName = ste.methodName | |
builder.append(className).append("#").append(methodName).append("\n") | |
} | |
Timber.d(">>> Trace log : $builder") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment