Skip to content

Instantly share code, notes, and snippets.

@rayworks
Last active October 20, 2020 09:42

Revisions

  1. rayworks revised this gist Oct 20, 2020. 1 changed file with 17 additions and 18 deletions.
    35 changes: 17 additions & 18 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -1,20 +1,19 @@
    public static void printCallerContextInfo(){
    StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();

    int i = 0;
    int levelDepth = 5;
    StringBuilder builder = new StringBuilder();
    builder.append("Sync is disabled in caller : ");
    for (StackTraceElement ste:stackTrace) {
    i++;
    if(i > levelDepth) {
    break;
    }
    fun printCallerContextInfo(cb: () -> String, levelDepth : Int = 7) {
    if (!BuildConfig.DEBUG)
    return

    String className = ste.getClassName();
    String methodName =ste.getMethodName();

    builder.append(className).append("#").append(methodName).append("\n");
    }
    Log.d("Tag", builder.toString());
    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")
    }
  2. rayworks created this gist Oct 19, 2020.
    20 changes: 20 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@
    public static void printCallerContextInfo(){
    StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();

    int i = 0;
    int levelDepth = 5;
    StringBuilder builder = new StringBuilder();
    builder.append("Sync is disabled in caller : ");
    for (StackTraceElement ste:stackTrace) {
    i++;
    if(i > levelDepth) {
    break;
    }

    String className = ste.getClassName();
    String methodName =ste.getMethodName();

    builder.append(className).append("#").append(methodName).append("\n");
    }
    Log.d("Tag", builder.toString());
    }