Skip to content

Instantly share code, notes, and snippets.

@rayworks
Last active October 20, 2020 09:42
Show Gist options
  • Save rayworks/89a6fb719c0a9aa53c25f09691b97b4f to your computer and use it in GitHub Desktop.
Save rayworks/89a6fb719c0a9aa53c25f09691b97b4f to your computer and use it in GitHub Desktop.
Prints Caller function names
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