logback-android/src/main/java/ch/qos/logback/classic/spi/CallerData.java
public static StackTraceElement[] extract(Throwable t,
                                            String fqnOfInvokingClass, final int maxDepth,
                                            List<String> frameworkPackageList) {
    if (t == null) {
      return null;
    }

    StackTraceElement[] steArray = t.getStackTrace();
    StackTraceElement[] callerDataArray;

    int found = LINE_NA;
    for (int i = 0; i < steArray.length; i++) {
      if (isInFrameworkSpace(steArray[i].getClassName(),
              fqnOfInvokingClass, frameworkPackageList)) {
        // the caller is assumed to be the next stack frame, hence the +1.
        found = i + 1;
      } else {
        if (found != LINE_NA) {
          break;
        }
      }
    }

    // we failed to extract caller data
    if (found == LINE_NA) {
      return EMPTY_CALLER_DATA_ARRAY;
    }

    int availableDepth = steArray.length - found;
    int desiredDepth = maxDepth < (availableDepth) ? maxDepth : availableDepth;

    callerDataArray = new StackTraceElement[desiredDepth];
    for (int i = 0; i < desiredDepth; i++) {
      callerDataArray[i] = steArray[found + i];
    }
    return callerDataArray;
  }
public static StackTraceElement[] extract(Throwable t,
                                            String fqnOfInvokingClass, final int maxDepth,
                                            List<String> frameworkPackageList) {
    if (t == null) {
      return null;
    }

    StackTraceElement[] steArray = t.getStackTrace();
    StackTraceElement[] callerDataArray;

    int found = LINE_NA;
    for (int i = 0; i < steArray.length; i++) {
      if (isInFrameworkSpace(steArray[i].getClassName(),
              fqnOfInvokingClass, frameworkPackageList)) {
        // the caller is assumed to be the next stack frame, hence the +1.
        found = i + 1;
      } else {
        if (found != LINE_NA) {
          break;
        }
      }
    }

    // we failed to extract caller data
    if (found == LINE_NA) {
      return EMPTY_CALLER_DATA_ARRAY;
    }

    int availableDepth = steArray.length - found;
    int desiredDepth = maxDepth < (availableDepth) ? maxDepth : availableDepth;

    callerDataArray = new StackTraceElement[desiredDepth];
    for (int i = 0; i < desiredDepth; i++) {
      callerDataArray[i] = steArray[found + i];
    }
    return callerDataArray;
  }
public static StackTraceElement [ ] extract ( Throwable t , String fqnOfInvokingClass , final int maxDepth , List < String > frameworkPackageList ) { if ( t == null ) { return null ; } StackTraceElement [ ] steArray = t . getStackTrace ( ) ; StackTraceElement [ ] callerDataArray ; int found = LINE_NA ; for ( int i = 0 ; i < steArray . length ; i ++ ) { if ( isInFrameworkSpace ( steArray [ i ] . getClassName ( ) , fqnOfInvokingClass , frameworkPackageList ) ) { // the caller is assumed to be the next stack frame, hence the +1. found = i + 1 ; } else { if ( found != LINE_NA ) { break ; } } } // we failed to extract caller data if ( found == LINE_NA ) { return EMPTY_CALLER_DATA_ARRAY ; } int availableDepth = steArray . length - found ; int desiredDepth = maxDepth < ( availableDepth ) ? maxDepth : availableDepth ; callerDataArray = new StackTraceElement [ desiredDepth ] ; for ( int i = 0 ; i < desiredDepth ; i ++ ) { callerDataArray [ i ] = steArray [ found + i ] ; } return callerDataArray ; }
Extract caller data information as an array based on a Throwable passed as
parameter

@param t Throwable to extract data from
@param fqnOfInvokingClass Fully qualified name of invoking class
@param maxDepth maximum stack depth
@param frameworkPackageList list of framework package names to search
@return caller stack trace array
Extract caller data information as an array based on a Throwable passed as parameter